U.S. stocks moved higher late Wednesday morning after jumping between gains and losses in volatile trading as Wall Street weighed a surprising victory by Republican Donald Trump in the presidential election. 

The S&P 500 rose 0.3%, the Dow Jones Industrial Average gained 0.5% and the Nasdaq rose 0.2%.

European stocks were trading higher following losses earlier in the trading session. 

Trump, who will serve as the 45th president of the United States, surprisingly won New Hampshire, North Carolina, Florida, and Wisconsin, key battleground states both candidates needed to secure to win the election. Prior to the election, markets were factoring in a win by Democratic nominee Hillary Clinton, who is expected to address her supporters Wednesday morning.

The election saw Senate and House Republicans maintain their majorities in Congress.

"We think the stock market selloff will be short lived," Deutsche Bank analysts wrote in a note. "This apparent Republican sweep is positive for the broad market and especially health care stocks. The only sector that might suffer from this election outcome is energy, as we think a greater U.S. oil supply outlook weighs on the oil price recovery."

The energy sector turned higher Wednesday after seeing losses earlier in the session. The Energy Select Sector SPDR ETF  (XLE - Get Report)  was up 0.5%. But SunPower (SPWR - Get Report) fell 14% as investors believe Trump's focus on coal and oil is seen as a negative for the global energy company. 

Domestic crude oil supplies increased by 2.4 million barrels in the week ended Nov. 4, according to the U.S. Energy Information Administration. West Texas Intermediate crude oil was trading down 0.7% to $44.67 a barrel.

Health care stocks were rising Wednesday in reaction to Trump's victory. Biotech stocks, including Gilead Sciences (GILD - Get Report) , Celgene (CELG - Get Report) and Biogen (BIIB - Get Report) were higher as was the iShares Nasdaq Biotechnology exchange-traded fund (IBB - Get Report) that tracks these stocks. The ETF rose 7.7% in trading Wednesday. Drugmaker Pfizer (PFE - Get Report) was up 7%.

A Hillary Clinton victory and a Democratic takeover of Congress would have been the worst-case scenario for biotech and drug stocks given her relentless criticism of rising drug costs and promises to curb them. Trump hasn't been as vocal or openly hostile to drug companies, but he hasn't embraced or even defended their pricing practices, either, wrote TheStreet's Adam Feuerstein.

Financial stocks saw a jump as Bank of America (BAC - Get Report)  shares rose 4%, Wells Fargo (WFC - Get Report)  gained 3.3%, and JPMorgan Chase (JPM - Get Report)  shares bounced 3.4%.  The SPDR Financial Sector exchange-traded fund  (XLF - Get Report)  that tracks the financial-services sector was up 1.9% Wednesday.

"The re-pricing of everything has already begun," Stephen Guilfoyle, Stuart Frankel's chief market economist, wrote in a note. "Donald Trump has some isolationist ideas, but is not as anti-trade as presented in the media. His administration will likely be pro-business. His economics are pro-growth in the short-term. Reduced taxes, and increased fiscal spending provided by increased borrowing should produce a higher GDP."

Investors will be assessing the Federal Reserve's next move to determine whether the U.S. central bank will raise interest rates at its December meeting as the U.S. economy has strengthened. An economist told the Associated Press that Trump's victory rules out a rate hike entirely.

"Given the adverse market reaction we have already seen, the Fed's planned December rate hike is now off the table," Paul Ashworth, chief U.S. economist at Capital Economics, told the AP. He said Fed Chair Janet Yellen and other top policymakers might even resign in the event of a Trump presidency, because his victory demonstrates that that many Americans share his view that the Fed has been "overtly political."

Safe-haven assets such as gold and government bonds moved higher on Wednesday as appetite for riskier assets fell.

Gold futures spiked more than 1% to $1,288.30 an ounce, while U.S. Treasury bond yields, which move in the opposite direction of their price, slumped to 1.957%.

Gold mining stocks jumped, including Barrick Gold (ABX)  2.3%, Newmont (NEM - Get Report)  up 3.8% and Goldcorp (GG)  up 6%. 

The Mexican peso fell at one point early Wednesday by more than 12% against the U.S. dollar. Throughout this election season, the peso has fallen when Trump's chances have risen as investors worried over the state of trade relations between the two countries under a Trump administration. Trump has promised to build a wall between the U.S. and Mexico.

Corrections Corporation of America (CXW - Get Report)  jumped 37% as investors anticipated the usage of prisons will increase with Trump's promise to deport illegal immigrants. 

Viacom (VIAB - Get Report) reported adjusted quarterly earnings of 69 cents a share, topping analysts' estimates by 3 cents. Revenue of $3.23 billion came in below forecasts.

Viacom investors will be looking for any commentary on a possible merger to reunite with CBS (CBS - Get Report) . Viacom shares fell 1% Wednesday. 

Wendy's (WEN - Get Report) shares were down more than 1.2% after the fast-food chain beat earnings estimates on revenue of $364 million.

Mylan (MYL - Get Report) , the maker of the allergic reaction emergency treatment, EpiPen, is scheduled to report earnings after the market closes, as is Shake Shack (SHAK - Get Report) .