Stocks ended little changed on Tuesday, paring gains after the Dow topped 13,000 for the first time since May 2008, and as higher oil prices damped prospects for the economy.

Greece's securing a bailout to avoid a disorderly default provided some support to stocks, but investors said the news had mostly been priced in to the market.

Fresh highs in oil prices gave investors a reason to sell. U.S. crude futures rose 2.5 percent to a nine-month high of $105.84 a barrel on Iran supply worries.

Since the start of the year, signs of improvement in the economy and stabilization of Europe's debt crisis have driven the Dow up 6.1 percent, while the S&P has climbed 8.3 percent.

The Dow ended at 12,965 after briefly climbing above the psychologically key 13,000. Wal-Mart was the biggest drag on the Dow, sliding after its quarterly profit came in short of expectations.

The S&P 500 ended within two points of the closing high from April 29.

Despite the upbeat news on Greece we're running into some minor selling pressure, given the extent of the rally we've seen, said Fred Dickson, chief market strategist at D.A. Davidson & Co. in Lake Oswego, Oregon.

In addition, gas prices across country are raising some questions about earnings, he said. Higher gasoline prices hurt corporate profits as consumers cut back on other spending and businesses' expenses rise.

The national price of gasoline climbed to $3.59 a gallon in the latest week, the Energy Information Administration said. Chevron shares rose 1.6 percent to $108.41, giving the Dow its biggest boost.

Euro zone finance ministers agreed on a 130 billion euro ($172 billion) rescue for Greece to avert a chaotic default after forcing Athens to commit to unpopular cuts and private bondholders agreed to take bigger losses.

Even with the bailout, Greece faces a long road to economic recovery. European Union officials said the Greek economy will only return to growth in 2014 after a recession that will shrink output by 17 percent.

It's not the end of the story there, said Bryant Evans, investment adviser and portfolio manager at Cozad Asset Management in Champaign, Illinois.

The Dow Jones industrial average <.DJI> finished up 15.82 points, or 0.12 percent, at 12,965.69. The Standard & Poor's 500 Index <.SPX> was up 0.98 point, or 0.07 percent, at 1,362.21. The Nasdaq Composite Index <.IXIC> was down 3.21 points, or 0.11 percent, at 2,948.57.

Wal-Mart shares fell 3.9 percent to $60.07, erasing most of the stock's gains so far in 2012.

Among the day's rising shares, Home Depot Inc was up 0.4 percent at $46.92 after the home improvement chain's quarterly profit beat estimates.

Macy's Inc climbed 1.2 percent to $36.69 as the department store chain posted higher profit and forecast more sales gains this year.

Kraft Foods Inc advanced 1.5 percent to $38.57 after the food company forecast earnings growth of at least 9 percent this year even as it prunes its portfolio of North American brands. Kraft, Wal-Mart and Home Depot are all Dow components.

Limiting losses on the Nasdaq, Apple Inc was up 2.5 percent to $514.85 after the U.S. International Trade Commission ruled the iPhone maker did not infringe patented technology owned by Android phonemaker HTC Corp <2498.TW>.

Volume was about 6.7 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, slightly below the daily average of 7 billion.

The number of declining stocks was about even with advancers on the NYSE, while on the Nasdaq decliners beat advancers by about 8 to 5.

After the closing bell, Dell Inc forecast fiscal first-quarter revenue below Wall Street's expectations. Its shares fell 4.7 percent to $17.36 in after-hours trading.

Software company Intuit Inc shares rose 2.9 percent to $59.21 after reporting a rise in quarterly revenue and profit.

(Reporting By Caroline Valetkevitch; Editing by Kenneth Barry)