Donald Trump had one more surprise up his sleeve.

The Republican nominee was elected president Tuesday, winning a stunning upset that defied nearly every prediction. Trump broke through Hillary Clinton’s Democratic firewall and turned back her bid to become the first woman to serve as president, even as the candidates battled for the lead in the popular vote.

Trump was carried to victory by a wave of right-wing populist nationalism, as working- and middle-class white Americans turned out in droves to vote for a candidate who had rejected Republican dogma during an erratic, peculiar campaign. Trump overperformed expectations in nearly every public poll, as well as the internal expectations of both parties.

The result, paired with Republican victories in the House and Senate, promises to remake American policy and politics, and the global order as well. It represents a wholesale repudiation of the establishment, from Washington to Wall Street. Even before Trump had clinched the win Tuesday night, markets around the world cratered and trading in stock futures was halted. The result is a disaster for the Democratic Party, which had put its faith in a repeat candidate representing a fading dynasty, could not win the Senate, and has few obvious young standard bearers waiting in the wings; the traditional conservative wing of the Republican Party, which largely broke with Trump; the media, which plainly detested Trump but fueled his movement with incessant coverage; and the political consulting and polling industry, which saw its methods ridiculed. It is also a body blow to the legacy of President Barack Obama. The nation’s first African American president will be succeeded by a man who built his political career on questioning whether Obama was a legitimate citizen.

Trump’s victory is an incredible finish to a campaign that often beggared belief. When Trump began his campaign in June 2015, proclaiming that Mexican immigrants were “bringing drugs. They’re bringing crime. They’re rapists,” he was widely viewed as a curiosity, a garish entertainer whose repeatedly unfulfilled political flirtations were the butt of jokes. Despite billing himself as a businessman, he garnered little respect within the business community. But Trump demolished what was touted as the most talented class of GOP politicians in a lifetime, winning the primary over the objections of most elected Republicans.

It is difficult to overstate the surprise of a Trump win, except perhaps with recourse to the infamous “Dewey Defeats Truman” headline of 1948. Polling averages never showed him leading, or only leading for a fleeting moment after the Republican National Convention. He centered his campaign around a promise to build a wall on the border with Mexico that practically no serious analyst believes is possible, and to force Mexico to pay for it, a remote possibility. He lost all three presidential debates. He rejected several key pillars of the Republican Party, including free trade, projecting American power abroad, and social conservatism. He broke longstanding tradition by refusing to release his tax returns, but bragged about having paid no income taxes for extended periods. During the campaign, The Washington Post published a video in which Trump boasted about sexually assaulting women, and about a dozen women came forward with allegations of sexual assault and harassment stretching across decades. He was a historically dishonest candidate, lying publicly on matters large and small, important and not, easily debunked and not. He would not commit to accepting the results of the election if he lost.

Trump’s campaign borrowed its tactics from Europe’s right-wing populist parties, eagerly leveraging race for political gain. He blamed immigration, whether from Latin America or from the Middle East, for many of the country’s ills, openly demonizing Hispanics and Muslims and railing against “political correctness.” He drew support from a resurgent white supremacist movement, passing along messages from anti-Semites and those who argue that a “white genocide” is occurring. He was endorsed by the Ku Klux Klan and wavered before rejecting the support of former KKK Imperial Wizard David Duke. These choices, along with his comments about women, produced a lopsided demographic result, with African Americans, Hispanics, and women backing Clinton by wide margins and white voters carrying Trump to the win.

Trump broke nearly every rule of political campaigning on the way to his win. He survived an unprecedented abandonment by members of his own party; even GOP officials who endorsed Trump often did so through gritted teeth. He lost the endorsements of even the most staunchly Republican newspapers. He barely engaged in fundraising for his race, beginning to ask for money only late in the game. Ultimately, Trump raised scarcely half of what Clinton did, and he hardly purchased ads to combat her onslaught of television spots, relying instead on social media and his own Twitter account. He eschewed traditional campaigning, from the construction of a field organization to the use of polling to the deployment of a carefully calibrated data analytics team, a tool that Obama’s two wins had established as a must. His unfavorable ratings lagged far behind even Clinton’s shoddy numbers, and national exit polls found a majority of Americans did not believe Trump was qualified to be president. He expressed a profound disgust for the First Amendment and a free press.

Clinton, meanwhile, was revealed as a badly damaged and weak candidate. She was never able to articulate a clear, concise purpose for her campaign, positioning herself more than anything as the only person who could stop Trump. Her long resume—stretching from her time as first lady through stints in the Senate and as secretary of state—turned out to be a liability. So, crucially, did her use of a private email server while leading the State Department. Democrats were quick to point a finger at FBI Director James Comey, whose announcement of new emails pertinent to the investigation of that server shook the race, but whose statement eight days later that the emails did not change his conclusion may have come too late to save Clinton. But the signs of her weaknesses were apparent before then, when she struggled to dispatch a primary challenge from Senator Bernie Sanders.

In the closing weeks of the campaign, Clinton—never a compelling orator—called on an all-star team of Democrats and others to buoy her, including Obama, Michelle Obama, Sanders, Vice President Biden, and a host of stars of sports, music, and movies. The Trump win in the face of his unified support from the elites in nearly every field underlines the vast split between them and Trump’s base. With both Clinton and Sanders near the ends of their career, it is unclear what the future Democratic Party will look like or who will lead it. The party will take cold comfort even if it does end up winning the popular vote in six of the last seven presidential elections.

A Trump presidency will present the largest shift in U.S. foreign policy since the nation became a superpower. He has offered an isolationist vision of American foreign policy, arguing that the United States does not get out of international alliances like NATO what it puts in, suggesting he would recognize Russian annexation in Eastern Europe and Central Asia. (He was rewarded with the support of Russian President Vladimir Putin.) He has promised to renegotiate existing free-trade agreements and promised the return of tariffs. He has spoken disdainfully of climate-change agreements and has suggested nuclear proliferation could help create global peace.

Domestically, Trump is expected to cut closer to standard Republican fare, though his plain lack of interest in policy details makes it more difficult to predict. He supports lower taxes and subscribes to supply-side economics, though he has also promised not to cut entitlements like Social Security and Medicare. With the likely outcome that the lame-duck Senate will continue to stonewall Obama nominee Merrick Garland, Trump will likely have the chance to nominate at least one and perhaps several more justices to the Supreme Court. He has promised to repeal the Affordable Care Act, better known as Obamacare.

Assuming he is able to mend fences with Republicans—not necessarily a sure bet—GOP majorities in both the House and Senate will give him broad maneuvering room to enact his policies. The Republican advantage in both the House and Senate decreased, but the party was able to hold both chambers, against expectations that a Clinton win would carry Democrats to a Senate edge. Democrats took over a seat in Illinois and held a seat in Nevada, they failed to pick up any of the other contested seats without Clinton’s coattails.

From the top of the ballot to the bottom, the election shows how deeply divided the nation remains. While Trump performed better that Mitt Romney in urban areas, a stark split between cosmopolitan, liberal urban areas and more conservative, whiter rural ones is a defining feature of the United States, along with a large gap in income and inequality. In other races across the nation, Republicans made big gains in some state houses, while voters in several other states opted to legalize recreational marijuana. In Maricopa County, Arizona, longtime Sheriff Joe Arpaio, a noisy Trump backer and opponent of immigration, was turned out of office. These divisions will likely manifest in increasingly disparate blue and red Americas, often colliding violently.

It will take days if not weeks for a full accounting of how polls failed to capture Trump’s surge so badly. He had promised that he would win with the help of the “silent majority,” a phrase he borrowed from Richard Nixon. That prediction was ridiculed by the smart money, along with suggestions that there might be large numbers of “shy” Trump voters unwilling to publicly declare their support. Trump’s win joins in a recent string of shocking upset victories for populist causes, from the rise of right-wing national parties in Europe to the Brexit vote to Colombia’s rejection of a peace referendum.

In the home stretch of the campaign, Trump had taken to referring to himself as “Mr. Brexit,” a nod to the unexpected result in that referendum. But as some analysts pointed out, the late polls there indicated that Leave would win. Trump’s victory is something far more surprising. But just as the United Kingdom is trying to sort through what Brexit might mean, Trump and the nation will have to figure out what the United States looks like now.