WASHINGTON — Pulling off a stunning upset, Republican real estate mogul Donald Trump was elected as the next president of the United States early Wednesday morning, becoming the first person to assume the office with no government or military background.

In a campaign marred by controversies and insults, the American people chose a total political outsider who vowed to clean up Washington — “drain the swamp,” as he put it.

At the New York Hilton Midtown in Manhattan, Trump celebrated his win shortly before 3 a.m. on Wednesday. He thanked supporters — many wearing his iconic red “Make America Great Again” caps — and adopted a conciliatory tone that was markedly different from the divisive rhetoric he used on the campaign trail.

“Now it’s time for America to bind the wounds of division. We have to get together. To all Republicans and Democrats and independents across this nation, I say, it is time for us to come together as one united people,” the president-elect said, calling on his opponents to work with him. “I pledge to every citizen of our land that I will be president for all Americans. This is so important to me.”

Since the end of July, Democratic presidential nominee Hillary Clinton, running to be the first woman president, held a polling lead over Trump, according to RealClearPolitics survey averages.

However, as returns came in Tuesday night into Wednesday morning, the actual picture was much different. The Republican standard-bearer secured the magic number — 270 electoral votes — shortly after 2:30 a.m., carrying all three crucial battleground states of Florida, Ohio and North Carolina. He also flipped reliably blue states, such as Pennsylvania and Wisconsin.

Clinton addressed a crowd of supporters and staffers at the New Yorker Hotel shortly before midday, delivering the final speech of her campaign and calling on supporters to accept the result of the election. She also emphasized the importance of the country coming together to build a nation and to respect the rights and privileges guaranteed by the Constitution.

“This is painful and it will be for a long time,” she said. “But I want you to remember this: Our campaign was never about one person or even one election. It was about the country we love and about building an America that’s hopeful, inclusive and big-hearted.”

Striking an optimistic tone, she told her audience — especially young people — to keep fighting for what they believe in. “Our best days are still ahead of us,” she said.

“Donald Trump is going to be our president. We owe him an open mind and the chance to lead,” she said. 

At the White House, President Barack Obama said he looked forward to helping the new president be successful, emphasizing that America needs a sense of unity during the upcoming transition.

“I want to make sure the hand-off is well executed, because ultimately we’re all on the same team,” Obama said.

Obama, in remarks in the Rose Garden, reminded the nation that he and former President George W. Bush also had differences to sort out eight years ago, but ultimately managed a successful transition. He expects the same for Trump and invited him to the White House on Thursday.

The president also had a message for young voters, urging them to remain hopeful despite what some of them view as a disappointing outcome.

“You have to stay encouraged. Don’t be cynical. Don’t ever think you can’t make a difference,” he said.

At 70, Trump will be the oldest candidate to assume the office of the presidency. He told his supporters at a victory rally early Wednesday that Clinton had conceded in a phone call and congratulated him on his victory.

At one point during election night, the Dow Jones Industrial Average for futures took a more than 700-point dive, apparently in response to the anticipated results, but the sharp decline pared back overnight.

Throughout his campaign, Trump has positioned himself in stark contrast to Clinton and her decades of experience in the public spotlight. A one-time corporate lawyer, Clinton has served as a senator from New York, President Barack Obama’s secretary of state and first lady of both Arkansas and the country when her husband Bill Clinton served as governor and then as president.

Clinton had also outspent her billionaire rival. As of Oct. 19, the Clinton campaign has raised nearly $498 million dollars, double the $247.5 million Trump’s campaign collected, Federal Election Commission filings show.

However, Clinton has been heavily criticized by many who condemn her lack of transparency. She has refused to release transcripts of paid Wall Street speeches and was evasive about her use of a private email server during her tenure as secretary of state — an issue that has plagued her candidacy since the beginning and right up to Election Day.

FBI Director James Comey threw the political world into frenzy late October, saying the bureau was investigating new emails related to Clinton’s mishandling of classified information. Less than two weeks later, Comey said Sunday the July decision to not recommend criminal charges would stand.

Clinton’s historic candidacy — the closest a woman has ever gotten to the top White House spot — is bittersweet for many who expected her to break the gender glass ceiling. At the Javits Center in New York, where Clinton held her election night headquarters, the evening ended with staffers and supporters aghast and in tears.

The political heartbreak for the Democrats didn’t end there. Despite high hopes entering Nov. 8, they were unable to flip the five seats needed to take control of the Senate.

Although Trump lacks the traditional pedigree of a president, he has rallied a core group of supporters based on his outsider appeal and anti-establishment views.

He ran his campaign on change — the same, but also very different message that Barack Obama ran on in 2008. Trump vowed to clean up the corrupt Washington that he said “Crooked Hillary” represented. He said he would tear up trade deals unfavorable to the U.S. and hit back hard at the terrorist group ISIS.

However, his suggestions — such as forcing Mexico to pay for a U.S.-Mexico border wall and temporarily banning Muslims from entering the country — were condemned by critics as racist and xenophobic. Several women accused him of improper sexual advances after a 2005 “Access Hollywood” tape was released, in which he made lewd comments about women. His refusal to disclose his tax returns, which breaks with historical precedent, has raised questions about his business acumen and whether he paid any federal income taxes.

But he retained passionate support, especially among voters angry about the direction of the country since the Great Recession. They loved his blunt talk and disdain for political correctness. That support showed through Tuesday, with neck-and-neck voting returns in states that many had expected to go Clinton’s way.

“Nothing we want for our future is beyond our reach,” he said during his victory speech. “America will no longer settle for anything less than the best. We must reclaim our country’s destiny and dream big and bold and daring.”

Lauren Bally and Eunice Lee contributed reporting.