The S&P 500's gains erased the losses of Tuesday, when the index posted its first 1 percent drop in May. Fears about instability in Italy and the possibility of the country's exit from the euro sent investors piling into safety assets on Tuesday. The U.S. Treasury market, on a total return basis, on Tuesday had its best day since at least July 2011, according to the Bloomberg Barclay's Treasury Aggregate Index.

Stocks reversed Tuesday's slide as Italy's 5-Star Movement made a renewed attempt to form a coalition government and called for euroskeptic Paolo Savona to withdraw his candidacy as economy minister.

The Italian government's successful auction of five- and 10-year bonds also assuaged concerns about the country's ability to finance itself after a sell-off in bonds on Tuesday resulted in the biggest one-day surge for two-year yields in 26 years.

Energy stocks <.SPNY> posted the biggest gains of the 11 major sectors of the S&P 500. The energy index rose 3.1 percent, its biggest one-day gain in seven weeks, as U.S. crude oil prices settled up 2.2 percent.

"The risk of Italy leaving the euro is remote," said Kate Warne, investment strategist at Edward Jones in St. Louis. "It's a source of volatility but not a source of true concern for the financial markets."

The Dow Jones Industrial Average rose 306.33 points, or 1.26 percent, to 24,667.78, the S&P 500 gained 34.15 points, or 1.27 percent, to 2,724.01, and the Nasdaq Composite added 65.86 points, or 0.89 percent, to 7,462.45.

The Russell 2000 index of small-cap stocks <.RUT> rose 1.5 percent to end at an all-time closing high, buoyed by data confirming the strength of the U.S. economy. Small-cap U.S. companies generally are more domestically focused than their large-cap counterparts.

Payroll processor ADP's monthly report showed U.S. private sector employment increased by 178,000 jobs in May. The Commerce Department revised its estimate of first-quarter gross domestic product growth slightly downward, but economists estimate that GDP growth in the second quarter would rise above a 3 percent annual rate.

Cloud-based business software maker Salesforce.com rose 1.9 percent and computer and printer maker HP Inc jumped 4.0 percent after both companies raised their full-year profit forecasts.

Advancing issues outnumbered declining ones on the NYSE by a 4.05-to-1 ratio; on Nasdaq, a 2.13-to-1 ratio favored advancers.

The S&P 500 posted 28 new 52-week highs and two new lows; the Nasdaq Composite recorded 197 new highs and 33 new lows.

Volume on U.S. exchanges was 6.83 billion shares, compared to the 6.59 billion average for the full session over the last 20 trading days.

(Additional reporting by Medha Singh in Bengaluru; Editing by James Dalgleish and Leslie Adler)

By April Joyner