WASHINGTON — Former President Donald Trump was elected the 47th president of the United States on Wednesday, an extraordinary comeback for an ex-president who refused to accept defeat four years ago, sparked a violent insurrection at the U.S. Capitol, was convicted of felony charges and survived two assassination attempts.

With a win in Wisconsin, Trump cleared the 270 electoral votes needed to clinch the presidency. He won Michigan on Wednesday afternoon, sweeping the “blue wall” along with Pennsylvania — the one-time Democrat-leaning, swing states that all went for Trump in 2016 before flipping to President Joe Biden in 2020.

Trump’s Democratic rival, Vice President Kamala Harris, called Trump on Wednesday afternoon to concede the race and congratulate him.

A short time later, Biden also called Trump to congratulate him and to invite the president-elect to the White House, formally kicking off the transition ahead of Inauguration Day, the White House said.

Biden also called Harris.

Foreign leaders called Trump, too, including Israeli Prime Minister Benjamin Netanyahu and French President Emmanuel Macron.

The victory validates Trump’s bare-knuckles approach to politics. He had attacked Harris in deeply personal — often misogynistic and racist — terms as he pushed an apocalyptic picture of a country overrun by violent migrants.

The coarse rhetoric, paired with an image of hypermasculinity, resonated with angry voters — particularly men — in a deeply polarized nation.

“I want to thank the American people for the extraordinary honor of being elected your 47th president and your 45th president,” Trump told throngs of cheering supporters in Florida even before his victory was confirmed.

In state after state, Trump outperformed what he did in the 2020 election while Harris failed to do as well as Joe Biden did in winning the presidency four years ago. Upon taking office again, Trump will work with a Senate that will now be in Republican hands, while control of the House hadn’t been determined.

“We’ve been through so much together, and today you showed up in record numbers to deliver a victory,” Trump said. “This was something special and we’re going to pay you back,” he said.

In his second term, Trump has vowed to pursue an agenda centered on dramatically reshaping the federal government and pursuing retribution against his perceived enemies.

Trump will inherit a range of challenges when he assumes office Jan. 20, including heightened political polarization and global crises that are testing America’s influence abroad.

His win against Harris, the first woman of color to lead a major party ticket, marks the second time he has defeated a female rival in a general election. He beat Hillary Clinton in 2016. Harris rose to the top of the ticket after Biden, 80, exited the race amid alarm about his advanced age.

Trump is the first former president to return to power since President Grover Cleveland in 1892. Trump is the first person convicted of a felony to be elected president and, at 78, is the oldest person elected to the office. His vice president, Ohio Sen. JD Vance, 40, will become the highest-ranking member of the millennial generation in the U.S. government.

Trump has plans to swiftly enact a sweeping agenda that would transform nearly every aspect of American government.

His GOP critics in Congress have largely been defeated or retired. Federal courts are now filled with judges he appointed. The Supreme Court, which includes three Trump- appointed justices, issued a ruling this year affording presidents broad immunity from prosecution.

Trump’s language and behavior during the campaign sparked warnings from Democrats and some Republicans about shocks to democracy that his return to power would bring. He repeatedly praised strongman leaders, warned that he would deploy the military to target political opponents he labeled the “enemy from within,” threatened to take action against news organizations for unfavorable coverage and suggested suspending the Constitution.

While Harris, 60, focused much of her initial message around themes of joy, Trump channeled a powerful sense of anger and resentment among voters.

He seized on frustrations over high prices and fears about crime and migrants who illegally entered the country on Biden’s watch.

He also highlighted wars in the Middle East and Russia’s invasion of Ukraine to cast Democrats as presiding over — and encouraging — a world in chaos.

When he arrived in Washington in 2017, Trump knew little about the levers of federal power. His agenda was stymied by Congress and the courts, as well as senior staff members who took it upon themselves to serve as guardrails.

This time, Trump has said he would surround himself with loyalists who will enact his agenda, no questions asked, and who will arrive with hundreds of draft executive orders, legislative proposals and in-depth policy papers in hand.