ATLANTA ― Former Labor Secretary Tom Perez was elected chair of the Democratic National Committee on Saturday after a contentious race that highlighted divisions within the party.

Perez bested Rep. Keith Ellison (D-Minn.), the only other candidate remaining in the race after an inconclusive first round of voting. The final tally was 235 for Perez and 200 for Ellison.

Perez will now begin the work of rebuilding a Democratic Party battered by historic electoral losses as it is undertakes the task of confronting President Donald Trump and his agenda.

He also will have to win the trust of those who supported Ellison, his chief opponent. Many progressive activists who backed Sen. Bernie Sanders (I-Vt.) in the 2016 presidential primary viewed Ellison’s candidacy as a way to secure a foothold in the party after Sanders’ defeat.

Perez immediately moved to appoint Ellison deputy DNC chair and accepted a hug from his rival on the conference room stage. “I’m asking you to give everything you’ve got to support Chairman Perez,” Ellison told his supporters.

Perez bashed Trump and the “know-nothing movement,” and vowed to lead Democrats to victory against the president in 2020.

“We are one family, and I know we will leave here united today, no doubt about that,” Perez said. “We are indeed the party that turns hardship into hope. We are the party that turns doubts into dreams.”

Jay Jacobs, a New York DNC member who whipped votes for Perez in the second round of voting, said some party leaders ultimately decided Ellison was too radical.

“You have to understand that on the emotional level, a lot of people liked Keith’s message, and liked the idea of the dramatic change,” said Jacobs, chair of the Nassau County Democratic Party on Long Island. “On the more intellectual level, we had a sense ― and I think this is what a lot of folks had a sense ― that this would shift the party too far to the left. That was the back and forth.”

Other DNC members who backed Perez cited reasons unrelated to policy or ideology. Massachusetts DNC member David O’Brien pointed to Perez’s experience running large organizations and said he was impressed with Perez on a personal level, having heard from him repeatedly in recent weeks.

“The fact that [Perez] said he wanted to change the culture [at the DNC], the fact that he has campaigned at the local level, the fact that he has run an organization ― and the way someone campaigns is instructive as to how they would govern,” O’Brien said.

Idaho Democratic Party executive director Sally Boynton Brown, U.S. Air Force veteran Sam Ronan, media strategist Jehmu Greene and attorney Peter Peckarsky withdrew after the first round of voting on Saturday. Ronan and Peckarsky endorsed Ellison, while Greene threw her support to Perez. South Bend, Indiana, Mayor Pete Buttigieg dropped out just before voting began, without endorsing anyone.

The party chair’s main role is to raise funds, recruit candidates and represent the party to the media. The job typically is neither coveted nor influential when a party controls the White House and the president’s choice takes precedence.

But when a party is out of power, as Democrats are now, the race for chairmanship reflects competition among rival factions over how best to re-orient the party for future elections. In addition to losing control of the White House in 2016 and failing to retake either house of Congress, Democrats have lost almost 1,000 state legislature seats since 2009.

To complicate matters, the Democratic Party is divided along ideological lines. Some progressives who backed Sanders in the presidential primary remain convinced that the DNC favored Hillary Clinton, and that the party failed to channel Sanders’ populist economic message in the campaign against Trump.

Shortly after Trump’s victory, Sanders and prominent Clinton supporters like Senate Minority Leader Chuck Schumer (D-N.Y.) coalesced behind Ellison’s candidacy in an apparent effort to unite the party.

Perez entered the race in mid-December, reportedly after aides to then-President Barack Obama encouraged him. He has proven a formidable adversary for Ellison, picking up support from key Obama administration figures like former Vice President Joe Biden and former Attorney General Eric Holder.

Shortly after Perez’s victory, Obama issued a statement congratulating him. “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,” Obama said.

Perez pitched his federal executive experience, but he drew criticism for his public support of the now-defunct Trans-Pacific Partnership trade agreement while serving in Obama’s Cabinet. Like Ellison, Perez has a stellar reputation in progressive circles, leading some liberals to downplay the significance of a Perez victory.

Ellison, a congressman since 2007, pointed to his electoral success and his previous career as an organizer. He was hobbled early in the race by concerns about his past ties to the Nation of Islam, and leaked audio of controversial remarks he made about Israel at a 2010 fundraiser.

Over the course of a race that spanned over three months, all of the DNC candidates agreed the party desperately needs new, innovative leadership.

And across ideological lines, state party chairs and operatives have criticized the Obama administration’s formation of Organizing for Action, a fundraising and organizing arm that many Democrats say undermined party infrastructure. They also lament previous chairs’ lack of transparency and failure to attend to the needs of state and local parties.