Former US Labor Secretary Tom Perez edged Minnesota Rep. Keith Ellison by 35 votes Saturday to become the head of the Democratic National Committee.

He promptly called President Trump “the worst president in the history of the United States.”

After a months-long battle many Dems compared to a presidential primary, Perez outlasted Ellison in the second round of voting in Atlanta, securing 235 votes to Ellison’s 200. Perez had fallen one vote shy of the victory threshold in the first round of voting.

The results were another blow to Mayor de Blasio, who was in Atlanta to back Ellison.

Perez announced he would make Ellison “deputy chairman” of the DNC and embraced him from the podium after the vote.

Ellison wiped away tears, thanked his supporters, and said, “We don’t have the luxury of going out of this room divided.”

When Perez took the stage, he slammed President Trump and called for Democrats to remain engaged.

“They’re going to ask the question . . . where were you in 2017 when we had the worst president in the history of the US?” he said.

“We need every house call, we need to listen to people, we need to get back to basics, and we need to move forward,” he added.

The former Cabinet member earned the endorsements of several Obama administration alums, including former Vice President Joe Biden and former Attorney General Eric Holder.

"I am confident that when we lead lead with our values and lead with our actions, we succeed," Perez says of DNC https://t.co/T5uqoA85rO pic.twitter.com/bW9MRCVDsc — CBS News (@CBSNews) February 25, 2017

Ellison’s most high-profile backer was Vermont Sen. Bernie Sanders, but he also picked up support from Sen. Charles Schumer and Mayor de Blasio.

Democrats compared the race to a proxy war that refought the bruising 2016 primary between the left-wing Sanders and the party establishment led by Hillary Clinton.

Ellison enjoyed the support of the party’s upstart liberals, who saw his candidacy as a way to snatch a victory from November’s presidential defeat. Perez, who was on Clinton’s short list for vice president, was backed most strongly by Democratic stalwarts in the Obama and Clinton camps.

But Ellison, who is a Muslim, was damaged by criticism from pro-Israel organizations and slams from major Democratic donors who blasted his past associations with the Nation of Islam.