The 51-member body voted unanimously for Mark-Viverito, who becomes the first Hispanic person to hold the speaker's job.
Councilman Dan Garodnick abandoned his bid in the moments before the City Council's vote and threw his support behind Mark-Viverito.
"While it was difficult at times, that only makes today's show of unity even better," Mark-Viverito said after the vote. "We will work together because that is what New Yorkers expect and that is what New Yorkers deserve."
Garodnick, who represents a district on Manhattan's East Side, said he would work to resolve "any rifts this process may have caused among our colleagues" and to help the council move forward together.
Mark-Viverito is one of the most liberal members of the council and was an early supporter of de Blasio's mayoral bid.
De Blasio took the unusual step in recent weeks of injecting himself into the speaker's race, calling council members to lobby on his candidate's behalf.
The speaker is considered the second-most powerful post in city government and has the ability to speed up or obstruct the mayor's agenda.