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 the downward trend intact.

The Dow and the S&P 500 sharply rebounded, and the Nasdaq ended in solidly positive territory, on the Reuters report from Athens, based on sources with knowledge of the talks. The development set the stage for a hoped-for resolution to Greece's credit problems, which have hurt investor sentiment around the globe.

The Dow Jones industrial average <.DJI> was down 59.37 points, or 0.49 percent, to end unofficially at 12,050.30. The Standard & Poor's 500 Index <.SPX> was down 3.63 points, or 0.28 percent, to finish unofficially at 1,283.51. The Nasdaq Composite Index <.IXIC> was up 17.56 points, or 0.66 percent, to close unofficially at 2,686.75.

(Reporting by Ryan Vlastelica; Editing by Jan Paschal)