Former Labor Secretary and newly elected Democratic National Committee chair Tom Perez has already had a scuffle with President Donald Trump.

Perez was elected the new chairman after he beat Keith Ellison of Minnesota on a 235-200 vote on the second round.

Trump tweeted at him: 'Congratulations to Thomas Perez, who has just been named Chairman of the DNC. I could not be happier for him, or for the Republican Party!'

Trump seemed to imply that Perez would be a failure, thereby helping the Republican Party.

Scroll down for video

Former Labor Secretary and newly elected Democratic National Committee chair Tom Perez, left, has already had a scuffle with President Donald Trump

Trump tweeted at him: 'Congratulations to Thomas Perez, who has just been named Chairman of the DNC. I could not be happier for him, or for the Republican Party!' Trump seemed to imply that Perez would be a failure, thereby helping the Republican Party

But Perez responded with his own cheekiness. He wrote : 'Call me Tom. And don't get too happy. Keith Ellison and I, and Democrats united across the country, will be your worst nightmare'

But Perez responded with his own cheekiness.

He wrote: 'Call me Tom. And don't get too happy. Keith Ellison and I, and Democrats united across the country, will be your worst nightmare.'

Perez, a veteran of the Obama administration, will lead the daunting task of rebuilding the party and heading the opposition to Trump.

Members of the Democratic National Committee picked Perez on the second round of voting after one of the most crowded and competitive party leadership elections in decades.

Ellison was backed by liberal leader US Senator Bernie Sanders on a 235-200 vote.

After he was named chair, Perez picked runner-up Ellison to be deputy chairman in a show of unity.

Interim chair Donna Brazile (L) hands the gavel to newly-elected DNC Chair Tom Perez during the Democratic National Committee (DNC) Winter Meeting in Atlanta, Georgia

'We are suffering from a crisis of confidence, a crisis of relevance,' Perez told DNC members before the vote. He promised to lead the fight against Trump and change the DNC's culture to make it a more grassroots operation.

Trump was quick to congratulate him, tweeting: 'Congratulations to Thomas Perez, who has just been named Chairman of the DNC. I could not be happier for him, or for the Republican Party!'

During the gathering, Ellison stressed the need for a unified party despite the divisions between establishment Democrats who backed Perez and the liberal wing that favored Ellison.

Perez is the son of Dominican immigrants, while Ellison is the first Muslim elected to the US Congress.

Hillary Clinton congratulated Tom Perez on his win saying she is excited for a 'strong, unified party.' Perez endorsed Clinton during the 2016 presidential election

Senator Bernie Sanders, who had previously backed Ellison, congratulated Perez in a tweet after his win

The new DNC chair had been mentioned as Hillary Clinton's possible running mate during the 2016 presidential election. The 55-year-old Democratic leader later campaigned for Clinton and Kaine in the 2016 election.

Hillary Clinton tweeted: 'Congrats to [DNC chair Tom Perez] & deputy [Keith Ellison]. Excited for strong, unified party standing for best of our country into the future.'

Senator Bernie Sanders also congratulated Perez on Twitter shortly after his win along with former President Barack Obama.

'I congratulate Tom Perez on his election as chairman of the Democratic National Committee and look forward to working with him,' Sanders tweeted.

On Saturday Ellison stressed the need for a unified party despite the divisions between establishment Democrats who backed Perez and the liberal wing that favored Ellison

In a statement Obama said: 'Congratulations to my friend Tom Perez on his election to lead the Democratic Party, and on his choice of Keith Ellison to help him lead it.

'I’m proud of all the candidates who ran, and who make this great party what it is.

'What unites our party is a belief in opportunity – the idea that however you started out, whatever you look like, or whomever you love, America is the place where you can make it if you try.

'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.

'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.'

Earlier today, Democrats were still deadlocked over who should lead their party in the era of President Donald Trump, and headed to the second ballot. Perez fell within two votes of winning the party chairmanship during the first round.

Keith Ellison was about a dozen votes behind, leaving the race still undecided with 427 eligible party members set to vote again.

Earlier today, Democrats were still deadlocked over who should lead their party. Perez is seen celebrating above

The election of chairman of the Democratic National Committee has animated the hundreds of party officials, donors and activists who convened in Atlanta.

The unusually competitive race highlights the intensity of Democratic soul-searching after Hillary Clinton's presidential loss, which capped a pronounced slide in the party's fortunes from Washington to statehouses around the country.

The third-place finisher, Sally Boynton Brown of Idaho, dropped out but made no endorsement to suggest how her 12 supporters should vote. Neither did Mayor Pete Buttigieg of South Bend, Indiana, who dropped out just ahead of the first round of voting. Three other candidates remained on the ballot.

'We need a chair who cannot only take the fight to Donald Trump but make sure that we talk about our positive message of inclusion and opportunity and talk to that big tent of the Democratic Party,' Perez said.

DNC Chair Tom Perez (L) and newly-selected vice-chair Keith Ellison (R) reacts during the Democratic National Committee (DNC) Winter Meeting in Atlanta

Ellison told party faithful that they 'are the ones who are going to stand up, rise up and protect the American people.'

Both men promised aggressive rebuilding efforts for state and local Democratic parties.

The chair campaign has been uncharted territory as Democrats face a power deficit not seen in nine decades. Republicans control the White House, Congress and about two-thirds of US statehouses.

The GOP is one Senate confirmation fight away from a conservative majority on the Supreme Court.

With Democrats in agreement in their opposition to Trump, the race is likely to turn on who convinces enough DNC members to believe in his or her promises of rebuilding party infrastructure that withered under Obama despite his personal electoral success.

Ellison told voting members he has signatures from 750,000 rank-and-file Democrats who support his chairmanship bid. He promised to 'convert them from demonstration energy to electoral energy.' He pledged to prioritize small donations to finance the party, while working to 'organize this whole country.'

Perez said he would 'rebuild strong parties' and 'organize, organize, organize' so Democratic nominees could win 'from the school to the Senate in all the states.'

As he withdrew from the race, Buttigieg suggested that Democrats already have options for those races. 'There's nothing wrong with our bench,' said the 35-year-old mayor, pegged as a likely statewide candidate in Indiana. 'We just haven't called enough people on the bench ... and asked them to get out on the field.'

Perez got into the race at Obama's urging, but he has pushed back on the notion that represents the same 'establishment' label that dogged Clinton's presidential campaign. Ellison has endorsements from Vermont Sen. Bernie Sanders, who challenged Clinton for the Democratic nomination, and also from Senate Minority Leader Chuck Schumer.

For their parts, Ellison and Perez have praised each other and promised unity regardless of the outcome.

The winner will succeed outgoing Chairwoman Donna Brazile, who led the party as interim chief in the fallout from disclosure that internal party communications were stolen by hackers and leaked during the 2016 presidential campaign.