Stocks rose on Wednesday as energy shares jumped on the back of a strong rally in oil prices. The move higher follows President Donald Trump's decision to pull the U.S. out of the Iran nuclear deal.
The closed 0.9 percent higher at 2,697.79, with energy rising 2 percent. Occidental Petroleum was one of the best-performing stocks in the S&P 500, rising 5.4 percent.
Technology shares also boosted the broad index, rising 1.4 percent, while industrials, financials and materials also jumped.
The Dow Jones industrial average rose 182.33 points to 24,542.54, with Chevron and Exxon Mobil among the best-performing stocks in the index. The Nasdaq composite advanced 1 percent to close at 7,339.91.
Trump said Tuesday that the U.S. would be walking away from the Iran deal and that sanctions on the Middle Eastern country would be reinstated. In the run-up to the 2016 presidential election, this was a campaign promise that Trump had pledged.
"This would have been much more shocking a year ago (when [Brent] oil was US$50) than now (with oil at US$75)," said Hasnain Malik, head of equity research at Exotix Capital, in a note to clients.
"Longer term, this event further narrows the space for countries that would benefit from cooperation with both the US (and its closest regional allies Israel, Saudi and the UAE) and Iran to chart a neutral path, and may portend a weakening of the US-EU strategic relationship," Malik said.
Following the announcement, countries around the world reacted differently. While some nations in the Middle East commended the move made, U.S. allies in Europe did not. The president of Iran, Hassan Rouhani, said that his country would continue to commit to the nuclear deal, according to Reuters.
"Clearly, this is playing out in the energy sector," said Bill Northey, senior vice president at U.S. Bank Wealth Management. "But you've also got interest rates rising. That's impacting the rate-sensitive sectors of the market."
Utilities, a sector adversely affected by higher rates, was one of the worst-performing spaces on Wednesday, sliding 0.7 percent.
The 10-year Treasury yield broke above the 3 percent mark on Wednesday, a level that recently put markets on edge. The two-year note yield also traded at its highest level in nearly a decade.
Equities closed flat on Tuesday after a choppy trading session. Since late March, stocks have traded in a tight range, with the S&P 500 bouncing between its 50-day and 200-day moving averages, two key technical levels. The index closed slightly above the 50-day moving average on Wednesday.
"The market had traded up so much late last year and early this year," said Greg Luken, CEO of Luken Investment Analytics. "It takes time to digest that."
In corporate news, Walmart dropped 3.1 percent. The retailer's stock fell after it agreed to buy 77 percent of Flipkart for $16 billion. Flipkart is am e-commerce company based in India.
—CNBC's Tom DiChristopher contributed to this report