Donald Trump's surprise victory in the U.S. presidential race upended global markets early Wednesday, concluding one of the most divisive and unpredictable campaigns on record.

Stocks around the world quickly sold off, gold soared and the dollar fell sharply as Donald Trump defeated Hillary Clinton to become the 45th president of the U.S.

Financial markets weren't prepared.

As Mr. Trump took to the stage and vowed to begin the "urgent task of rebuilding our nation and renewing the American dream," risk assets initially set out on their steepest decline in months, before recovering many of those losses during early European trading hours.

"There is a bit of surprise, moderated panic even," said Nandini Ramakrishnan, global strategist at J.P. Morgan Asset Management. "We knew more or less what we were going to get with Clinton?a little bit less is certain about Trump."

Investors had largely counted on a narrow victory by Democratic candidate Hillary Clinton, who had been consistently leading in polls and betting markets right until roughly 9 p.m. Eastern time on Tuesday as polling results came in.

"The polls were wrong, but this time on the election of the president of the largest economy in the world," said Jordan Rochester, strategist at Nomura.

S&P 500 futures had tumbled as much as 5% as the polls pointed to a likely surprise victory for Mr. Trump, triggering a circuit breaker until U.S.markets open again. Brent crude oil shed over 3% as risk assets sold off, while gold climbed as much as 5% in a flight to safety before paring gains.

The yield on the 10-year Treasury note fell quickly from 1.896% to as low as 1.720% before recovering.

Global investors took note.

Japan's Nikkei Stock Average shed 5.4%, its biggest loss since Britain's June referendum, as the dollar fell to as low as ¥ 101.1940 against the yen.

European markets initially opened with a thud, as German's DAX shed 2.7% while markets in Spain and Italy shed over 3%. The export-heavy auto sector fared worse in the Stoxx Europe 600, shedding over 3% as the euro rose 0.9% against the dollar to $1.1115.

"When I felt the chances of Trump winning were increasing, I rushed into the office to warn clients," said James Butterfill, head of research and investment strategy at ETF Securities in London.

"We're worried of the geopolitical implications," he said,as well as what it means for the Federal Reserve and rising populist movements across Europe.

Losses in Europe began to moderate shortly after markets opened, with the Stoxx Europe 600 trading down just 0.8% midmorning, while S&P futures pared declines to 1.8%. Gains in gold eased.

Investors were also beginning to question the Federal Reserve's plans to raise interest rates in December, betting that a period of market turmoil following the surprise election result could keep the central bank on hold.

The WSJ Dollar Index fell sharply but recovered to trade flat after European markets opened.

The Mexican peso, which had moved closely in line with Mr. Trump's polling success during the election campaign, fell as much as 11% against the dollar before recovering to trade down 7.3%.

The move in the peso was particularly noteworthy on the trading floor of Mizuho Financial Group Inc.'s Americas unit in midtown Manhattan Tuesday night."That is a very big move, especially over 3.5 hours," said Dan Riveira, managing director in foreign-exchange trading at Mizuho Financial. "The peso is being used as a barometer for the election."

As the currency's value rapidly flashed in magenta on his screen, Mr. Riveira said this is the biggest move in the Mexican peso he can remember.

Chelsey Dulaney contributed to this article.

Write to Riva Gold at riva.gold@wsj.com, Ira Iosebashvili at ira.iosebashvili@wsj.com and Min Zeng at min.zeng@wsj.com

(END) Dow Jones Newswires

November 09, 2016 04:55 ET (09:55 GMT)

Copyright (c) 2016 Dow Jones & Company, Inc.