Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

ATLANTA — After a difficult 2016 campaign that saw them lose the White House, both chambers of Congress and state houses across the country, Democrats elected Tom Perez on Saturday to lead the Democratic National Committee and rebuild the party.

Perez, the former labor secretary in the Obama administration, won in a second round of voting and was considered the heavy favorite of the Democratic establishment. He earned 235 votes from the 447 DNC members — the voting bloc that decides the chairmanship.

"Team Tom means 'team,'" Perez said at the 2017 Winter DNC Meeting in Atlanta. "And as a team, we will work together."

Minnesota Congressman Keith Ellison, the preferred candidate of the Bernie Sanders wing of the party, came in second, earning 200 votes in the second round of votes.

Ellison said it was necessary to unite behind Perez for the party to move forward, and was appointed the party's deputy chairman.

"We don’t have the luxury, folks, to walk out of this room divided," Ellison said. "We don’t have that luxury, and I just want to say to you that it’s my honor to serve this party under Chairman Perez."

Interim chair Donna Brazile, left, hands the gavel to newly-elected DNC Chair Tom Perez. ERIK S. LESSER / EPA

The other five candidates dropped out of the race before the second round of votes.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Mayor Pete Buttigeig of South Bend, Indiana, did not make it to the voting process, announcing during his nomination speech earlier Saturday that he would be exiting the race. Buttigeig, 35, built a national profile as an emerging dark horse in the race for the chairmanship with the backing of former DNC Chairman Howard Dean.

"It looks like I’m not going to be the next chair," Buttigeig said. “But whoever is, I am urging to do the things that must be done to be open to change, to look beyond Washington, to not treat the presidency like it’s the only office that matters, to pay attention to communities like ours in the heart of our country — not as an exotic species — but as your fellow Americans."

The former Naval intelligence officer campaigned on the idea that the aging Democratic Party needs to empower its millennial members.

The 447 members of the Democratic National Committee voted Saturday afternoon, gathering in a ballroom to cast their ballots for chair and other party officer positions. Half ballots were given to Democrats voting abroad.

Perez is taking over from Interim DNC Chair Donna Brazile, who stepped into the role after the resignation of Rep. Debbie Wasserman Schultz last summer.

"While it will be bittersweet for me to leave this job and this tremendous organization, I’m confident that the future of the Democratic Party will be in good hands with Tom Perez," Brazile said in a statement. "And I want to congratulate all of the candidates for a race well run.”

On the eve of Saturday's election, Perez forces were feeling confident as they told Democrats they had pulled ahead, buoyed by the late endorsement of Jaime Harrison, the chairman of the South Carolina Democratic Party, who quit the chairman’s race Thursday to endorse Perez.

"We’re going to be unified and we’re going to get this thing done on the first ballot,” Harrison had told supporters Friday night.

After the second round of votes brought Perez the victory, Vermont Sen. Bernie Sanders offered his endorsement to the newly elected chair but added that Perez would need to be forward-thinking as the Democrats' new leader.

It's imperative Tom understands that the same-old, same-old isn't working and that we must bring in working and young people in a new way. — Bernie Sanders (@BernieSanders) February 25, 2017

President Barack Obama congratulated Perez in a statement, adding "I'm proud of all the candidates who ran, and who make this great party what it is."

"Over the past eight years, our party continued its track record of delivering on that promise: growing the economy, creating new jobs, keeping our people safe with a tough, smart foreign policy, and expanding the rights of our founding to every American including the right to quality, affordable health insurance," Obama said. "That's a legacy the Democratic Party will always carry forward.

"I know that Tom Perez will unite us under that banner of opportunity, and lay the groundwork for a new generation of Democratic leadership for this big, bold, inclusive, dynamic America we love so much."

The DNC's chief fundraiser, Henry Munoz, who is running unopposed for reelection as Finance Chairman, gave Perez a final boost late Friday with his endorsement after remaining neutral throughout the race.

After a four-month election, candidates in all camps spent the closing days saying whoever won the chair’s race need to heal the rift between the party’s establishment wing, represented by Perez, and anti-establishment side, which has rallied behind Ellison.

Congratulations to Tom Perez on his election as DNC Chair. I look forward to working w/ him to build a party that puts working people first. — Bill de Blasio (@BilldeBlasio) February 25, 2017

Candidates campaigned up until the last minute, buttonholing undecided DNC members at a hotel bar after midnight and host parties with live bands and free food.

Ringers were flown in to give candidates a final boost with the dwindling number of voters still not aligned with either candidate.

New York City Mayor Bill de Blasio towered over DNC members as he pressed his case for Ellison. "Keith Ellison is a man of destiny," he told them. "This is not an optional situation. We need Keith Ellison."

Meanwhile, Valerie Jarrett, the longtime confidant of former president Obama, phoned DNC members to support Perez, while Los Angeles Mayor Eric Garcetti reinforced Perez’ troops on the ground.