The markets recovered from its initial losses of over 317 points tracking weak Asian cues as Greek voters said 'no' to bailout terms as demanded by its creditors.
The Sensex, which had recaptured the 28,000 level, resumed lower at 27,857.20, slipped further to hit the day's low of 27,774.80.
However, it wiped off losses completely on the back of across-the-board buying at the fag end of the session and rebounded to the session's high of 28,235.31 before ending at 28,208.76, a gain of 115.97 points, or 0.41 per cent.
Similarly, the 50-share Nifty regained the 8,500 mark by rising 37.25 points, or 0.44 per cent, to end the day at 8,522.15 after shuttling between 8,386.15 and 8,533.15.
For both indices, the readings were the highest close in nearly 2-1/2 months.
In the Sensex pack, Dr Reddy's emerged as the major gainer by surging 3.64 per cent at Rs 3,711.75, followed by Cipla (3.35 per cent) at Rs 652.55.
Brokers said sentiment got a big push after Reserve Bank Governor Raghuram Rajan's comments last week that India's exposure to Greece is limited.
The major Sensex losers were Vedanta, Hindalco, NTPC, Tata Steel and Infosys.
Broader markets such as small-cap and mid-cap indices rose 1.09 per cent and 0.85 per cent, respectively.
Foreign portfolio investors (FPIs) net bought shares worth Rs 356.29 crore last Friday, according to provisional data.
Globally, Asian stocks ended lower while European markets were down in early trade as Greek voters' rejection of austerity proposals sent investors to the relative safety of Treasuries.
