Stocks closed way off session lows on Thursday on news Greece agreed to a five-year austerity plan, but lingering economic uncertainty ultimately drove indexes mostly lower, keeping a downward trend in place.
The Nasdaq wiped out all its losses, ending the session higher and back in the black for the year.
The news out of Greece set the stage for a resolution to Athens' credit problems, which have hurt investor sentiment around the globe.
"Shorts will unwind some positions, but this isn't the whole story," said Rich Ilczyszyn, market strategist with Lind Waldock in Chicago.
The question now remains whether the late-day surge is a precursor to renewed buying interest or if it was just an interruption before selling returns in coming days.
The S&P 500 came within less than a half point of its 200-day moving average — a line the bulls have been able to hold since last September. Technical analysts monitor that level as an indication of the long-term trend, and a consistent close below it could trigger more selling.
"We're at key support levels for everything, including the S&P," Ilczyszyn said.
Sources with knowledge of the talks told Reuters that Greece has won the consent of a team of European Union and International Monetary Fund inspectors for its new five-year austerity plan after committing to an additional round of tax increases and spending cuts.
The Dow Jones Industrial Average dropped 59.67 points, or 0.49 percent, to 12,050.00 at the close. The Standard & Poor's 500 Index lost 3.64 points, or 0.28 percent, to 1,283.50. But the Nasdaq Composite Index gained 17.56 points, or 0.66 percent, to 2,686.75.
Earlier in the day, markets had sold off as oil's slide to a four-month low triggered declines in a fragile market after Federal Reserve Chairman Ben Bernanke's comments about a slowing economic recovery a day earlier.
Skepticism remained despite the Greek deal as details were not yet known and any agreement would still have to win a vote in Parliament.
"When it's 3 o'clock on a Thursday afternoon and short-sellers see that (Greece deal) headline, they cover first and ask questions later," said Peter Boockvar, equity strategist at Miller Tabak & Co. in New York.
He said since there is already a plan awaiting a vote, the difference could be a change in terms that could make it easier to pass in the Athens Parliament next week.
U.S. August crude oil futures settled at $91.02 a barrel, down $4.39, after the International Energy Agency said it will release 60 million barrels of oil from strategic stockpiles.
The slide in the price of oil was exacerbated by a 0.7 percent climb in the U.S. Dollar Index, which tracks the greenback's performance against a basket of major currencies. In times of stress, the flight to safety that pushes the dollar higher makes oil more expensive, further sapping demand for crude and other commodities priced in dollars.
Giving some support to the market, tumbling oil prices lifted an index of airlines' stocks by 2.4 percent.
Bets that lower prices at the pump will open consumer's wallets boosted the S&P retail sector index by 1.4 percent.
The S&P 500's bounce off its 200-day moving average was the second in a week. Last Thursday, a brush with that level enticed buyers and the benchmark index closed in the black for the day. The 200-day moving average now coincides with the 2010 intraday high of 1,262.60, giving it extra technical support.
"What it means is that if you do momentum trading, you can place bets, and a lot of big money is doing momentum trading," said George Feiger, CEO of Contango Capital Advisors in San Francisco.
"But the big picture story remains the same. We are looking at small growth and very small return in equities for the coming years."
His view differs from the median of 46 equity strategists surveyed in the last week, which showed an expectation of an 11 percent gain in the S&P 500 for the year, which would take it to 1,400.
On the economic front, U.S. claims for unemployment benefits rose more than expected last week, suggesting little improvement in the labor market. Other data showed sales of new homes fell in May.
About 8.2 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, above the average so far this year of 7.57 billion. Volume got a late boost after the Greece headlines.
Declining stocks outnumbered advancing ones on the NYSE by a ratio of more than 4 to 3. On the Nasdaq, the opposite trend prevailed: About seven stocks rose for every six that fell.
© 2015 Thomson/Reuters. All rights reserved.