WASHINGTON (AP) — Donald Trump captured crucial victories over Hillary Clinton Tuesday night in Florida, Ohio and North Carolina, showing remarkable strength in three of the nation’s most fiercely fought battleground states in an unexpectedly tight race for the presidency.

By the time it was over, Trump had been declared the winner with 278 electoral votes to Clinton’s 218. The race was not decided until the wee hours of the morning.

Clinton carried Virginia and Colorado, as well as California, the nation’s largest prize. With a handful of other states still undecided, neither candidate had cleared the 270 Electoral College votes needed to win the White House.

Michigan and Wisconsin, two Midwestern powerhouses that haven’t voted for a Republican presidential candidate since the 1980s, took on unexpected importance. Clinton’s campaign had largely taken both for granted, but made a late push in Michigan in the race’s final days.

The uncertainty sent Dow Jones futures and Asian markets tumbling, reflecting investor concern over what a Trump presidency might mean for the economy and trade.

As Clinton’s team anxiously waited for results to roll in, the candidate tweeted to supporters, “Whatever happens tonight, thank you for everything.”

Clinton, a fixture in American politics for decades, was hoping to become the first woman to serve as commander in chief. She faced stiff competition from Trump, the billionaire businessman who tapped into a searing strain of economic populism.

Trump picked up a number of reliably Republican states, while Clinton won in Democratic territory. But the race was to be determined by fewer than a dozen competitive states where the candidates spent millions of dollars and much of the fall wooing voters.

Exit polls underscored the deep divisions that have defined the 2016 contest. Women nationwide supported Clinton by a double-digit margin, while men were significantly more likely to back Trump. More than half of white voters backed the Republican, while nearly 9 in 10 blacks and two-thirds of Hispanics voted for the Democrat.

Democrats’ path to retaking the Senate majority narrowed as Republicans held onto key seats in North Carolina, Indiana and Florida. The GOP was on track to secure two more years of House control.

The 45th president will inherit an anxious nation, deeply divided by economic and educational opportunities, race and culture. The economy has rebounded from the depths of recession, though many Americans have yet to benefit. New terror threats from home and abroad have raised security fears.

Clinton asked voters to keep the White House in her party’s hands for a third straight term. She cast herself as heir to President Barack Obama’s legacy and pledged to make good on his unfinished agenda, including passing immigration legislation, tightening restrictions on guns and tweaking his signature health care law.

But she struggled throughout the race with persistent questions about her honesty and trustworthiness. Those troubles flared anew late in the race, when FBI Director James Comey announced a review of new emails from her tenure at the State Department. On Sunday, just two days before Election Day, Comey said there was nothing in the material to warrant criminal charges against Clinton.

Trump, the New York real estate developer who lives in a gold-plated Manhattan penthouse, forged a striking connection with white, working-class Americans who feel left behind in the changing economy and diversifying country. He cast immigration, both from Latin America and the Middle East, as the root of many problems plaguing the nation and called for building a wall along the U.S.-Mexico border.

“I see so many hopes and so many dreams out there that didn’t happen, that could have happened, with leadership, with proper leadership,” he said by telephone on Fox News before casting his own ballot in Manhattan. “And people are hurt so badly.”

Seven in 10 Americans who went to the polls Tuesday said immigrants now in the country illegally should be allowed to stay, while just a quarter said they should be deported. More than half oppose building a border wall, according to the exit polls, which were conducted for The Associated Press and television networks by Edison Research.

The Republican Party’s tortured relationship with its nominee was evident right up to the end. Former President George W. Bush and wife Laura Bush declined to back Trump, instead selecting “none of the above” when they voted for president, according to spokesman Freddy Ford.

Trump set both parties on edge when he refused to say in the third and final debate whether he would accept the election’s results, citing with no evidence the possibility of a rigged outcome. His statement threatened to undermine a fundamental pillar of American democracy and raised the prospect that his fervent supporters would not view Clinton as a legitimate president if she won.

Asked Tuesday in an interview with Fox News if he would accept the election results, Trump continued to demur, saying “We’re going to see how things play out.”

Most problems that did pop up at polling places Tuesday appeared to be routine — the kinds of snags that come every four years, including long lines, machines not working properly and issues with ballots or voter rolls.

Even before Tuesday, almost 45 million people had cast ballots for president. Many expressed relief the end was in sight after an election season in which personal attacks often drowned out the issues.

Clinton has denounced Trump for calling Mexican immigrants “rapists” and promoting a ban on Muslims entering the U.S., and for his long line of remarks about women that culminated in an audio in which he bragged about grabbing their genitals. Her campaign was hoping high turnout among Hispanics push her over the top in states like Florida and Nevada.

“I grew up in a Hispanic family, and the way that Donald Trump has referred to illegal immigrants — being from illegal immigrants, I took that to heart,” said Angel Salazar, a 22-year-old sanitation associate from Oklahoma City. “I don’t like anything that he said. I don’t like his views. So I voted for Hillary Clinton because she supports us.”_

Supporters of Republican presidential candidate Donald Trump watch election results during an election night rally, Tuesday, Nov. 8, 2016, in New York.
https://www.newberryobserver.com/wp-content/uploads/2016/11/web1_AP_16314102931289A-1.jpgSupporters of Republican presidential candidate Donald Trump watch election results during an election night rally, Tuesday, Nov. 8, 2016, in New York. AP Photo | Evan Vucci

By Julie Pace and Robert Furlow

Associated Press

Associated Press writers Catherine Lucey, Bradley Klapper, Vivian Salama, Hope Yen, Jill Colvin and Lisa Lerer and AP Polling Director Emily Swanson contributed to this report.