Martin J. Walsh, a legislator and long-time labor leader, ground out a narrow victory over City Councilor John R. Connolly Tuesday to become Boston’s 48th mayor, propelled by a diverse coalition that transcended geography, race, and ideology.

Advertisement - Continue Reading Below

Walsh rode a wave of support that spanned Boston, from his Savin Hill neighbors to African-Americans in Roxbury, liberal activists in Jamaica Plain to Latinos in Hyde Park. His campaign — fueled by unprecedented spending by organized labor from across the country — swelled beyond his base in Dorchester, where Walsh, the son of Irish immigrants, grew up in a tripledecker.

Walsh beat Connolly, 52 percent to 48 percent, in final results posted on the city’s website.

“For this kid from Taft Street in Dorchester you’ve made Boston a place where dreams come true. Together we’re going to make Boston a place where dreams come true for every child and every person in every corner of this city,” Walsh told cheering supporters at his election night party at the Boston Park Plaza Hotel.

Walsh, who said he had just received congratulatory calls from President Obama and outgoing Mayor Thomas M. Menino, promised to work for “opportunity — because every woman, man and child deserves a chance; community — because that’s the strength of this city; equality —because everybody gets ahead, not just some.”

He said he wanted to make Boston a “community of shared prosperity.”

“In January, Boston begins a new era. We get to write a new chapter in its 400-year history. We know Boston is a strong city and a fortunate city. My mission is to make it better, to make Boston a hub of opportunity,” he said.

When Walsh takes office Jan. 6, it will mark the end of the 20-year tenure of Menino, whose announcement in March that he would not seek a sixth term unleashed a generation of pent-up political ambition.

In a race that lacked substantial policy differences, Walsh won as an everyman with a compelling life story. The 46-year-old spoke often about his immigrant roots, his battle with childhood cancer, his encounter with a stray bullet that grazed his leg after a night of drinking, and his struggle as a young man to overcome alcoholism. Walsh made up for a dearth of detail when discussing policy with his affable personality, which helped build trust, a trait that won key endorsements from black and Latino leaders.

The election marked the return of an Irish-American to the mayor’s office, a decades-long tradition that had been broken by Menino, the city’s first Italian-American mayor.

The election also brought the dawn of a new era in city politics, with a flood of money from outside groups and anonymous political committees nearly eclipsing spending by the candidates’ official campaigns. For organized labor, Walsh’s bid for mayor became a national cause as unions across the country contributed millions to the effort. Boston will be one of the rare major American cities to have a labor leader serve as mayor.

Walsh is 24 years younger than Menino, who was born during World War II and came of age as Boston convulsed with urban decay and the racial strife of court-ordered busing to desegregate schools.

Walsh is a child of the late 1960s whose formative years came in the aftermath of busing. He grew up in a polarized city, but he spent much of his campaign promoting a tolerant “one Boston.”

“If we set our sights high ... I promise you the best is yet to come,” Walsh told his jubilant supporters at the Park Plaza, with his girlfriend, Lorrie Higgins, by his side.

Connolly, at his election night party at The Westin Copley Place hotel, thanked supporters.

“I thank you for everything you did from Day One. ... You were all amazing, you gave me so much,” he said.

“I’ve known Marty Walsh 18 years,” Connolly said. “I knew Marty Walsh 10 years before I ever ran for office. Marty Walsh is a good man. He wants to do good things for Boston and he will do good things for Boston. And he has my full support. Marty has my full support.”

Menino announced March 28 he would “leave the job that I love” and not seek a sixth term, catching much of the Boston’s political establishment by surprise.

As the first open race for mayor in 20 years, the campaign sparked excitement in political circles but was largely overshadowed by the tragedy of the Boston Marathon bombings and the triumph of the Red Sox in the World Series. In between, the city was absorbed in the trial of notorious gangster James “Whitey” Bulger.

Walsh and Connolly were the two top votegetters in a Sept. 24 preliminary election, setting up a final six-week dash to today’s election.

Initial public polls showed Connolly, 40, who promised to be the “education mayor,” with a lead, but Walsh locked up a series of endorsements and gained momentum. Two failed mayoral candidates — former school committee member John F. Barros and City Councilor Felix G. Arroyo — both joined Walsh’s campaign. They were followed by former city housing chief Charlotte Golar Richie, who finished third in the preliminary election.

The endorsements of the three most prominent mayoral candidates of color became a potent symbol for Walsh, and other black elected officials soonfollowed. In the week before the election, public polls swung in Walsh’s favor.

The race turned increasingly bitter in its closing weeks, with Walsh and Connolly accusing each other of negative campaigning.

Connolly also charged in debates that Walsh, who worked as a union official while serving in the Legislature, was too closely tied to labor. But Walsh responded that because of his experience he could be a more effective negotiator with the city’s municipal unions.