Stocks nearly erased a three-day rally on Wednesday as energy and other commodity shares sank, feeding worries about the market's ability to stay on its upward path.

The second major breakdown in commodities in a week fueled selling in other risky assets, including stocks. A stronger dollar and data showing a rise in U.S. fuel supplies sent crude oil prices down more than 5 percent, and the S&P energy index <.GSPE> slid 3 percent.

A lot of money is tied up into things like exchange-traded funds and mutual funds that track a broad array of stocks and not just commodities. Some of this could be a shift out of equities in general, but especially energy and commodities, said Bryant Evans, investment adviser and portfolio manager at Cozad Asset Management in Champaign, Illinois.

About five stocks fell for every one that rose on the New York Stock Exchange, a broad exodus signaling investors saw little value in most industries.

The Energy Select Sector SPDR Fund fell 2.9 percent to $74.28 while the U.S. oil fund lost 4.2 percent to $39.35 and the iShares silver exchange-traded fund dropped 8.3 percent at $34.39.

Worries about global demand have fed losses in energy and materials shares. The S&P energy sector is now down 7.8 percent since the start of the month.

In a sign of weakness, the S&P 500 broke below 1,340, a key technical level, and some analysts said a close below 1,330 would be bearish for the market.

The Dow Jones industrial average <.DJI> was down 130.33 points, or 1.02 percent, at 12,630.03. The Standard & Poor's 500 Index <.SPX> was down 15.08 points, or 1.11 percent, at 1,342.08. The Nasdaq Composite Index <.IXIC> was down 26.83 points, or 0.93 percent, at 2,845.06.

The 1,340 level roughly coincides with the 20-day average, which the market has closed above since April 20. If the S&P 500 closes below that average, the Bollinger bands chart shows a near-term target just above 1,300.

In the foreign exchange market, the euro dropped to a three-week low against the dollar as investors unwound risky trades in commodities and higher-yielding currencies and bought back the greenback in a flight to quality bid.

U.S. government debt prices also rose in a safety bid.

Concerns about growth in China also hit cyclical sectors, which have teetered on worries about global demand. A report showed industrial output growth eased in April, suggesting China's economy was moderating the pace of expansion, although Chinese inflation remained high.

To be sure, many strategists saw the commodity declines as a long-term positive for the market, giving some relief from higher commodity costs to consumers and companies.

That was evident in some sharp gains in the consumer discretionary sector, said Carter Worth, chief market technician, Oppenheimer & Co in New York.

The breaking in fever of commodities ultimately is a positive, he said.

The S&P retail index <.RLX> ended the day up 0.06 percent. Shares of Macy's Inc jumped 7.7 percent to $28.36. The department store reported a profit that topped estimates and offered an optimistic outlook for the rest of 2011.

About 7.72 billion shares were traded on the NYSE, NYSE Amex and Nasdaq, compared with the average of 7.73 billion so far in 2011.

Declining stocks outnumbered advancing ones on the Nasdaq by a ratio of about 10 to 3.

(Reporting by Caroline Valetkevitch; Editing by Kenneth Barry)