The Sensex rose 180 points, or 0.34 per cent, to close at 52,974, while the Nifty50 ended at 15,842, with a gain of 60 points, or 0.38 per cent.
In the preceding six sessions, both indices had slumped over 5 per cent each.
This is only the second trading session in May when markets have been able to clock gains.
Foreign institutional investors (FPIs) have sold shares worth $3.3 billion in May, taking their year-to-date selling past $20 billion.
“Continued selling by FPIs — as they chase high-yield US bonds — restricts the Indian market to hold on to its pull-back rally, interest from domestic investors notwithstanding. Weakness in global equities, along with unfavourable global cues, led to heavy selling towards closing hours, as investors lacked the confidence to take forward their positions. The investors are currently in a risk-deleveraging phase, hunting for safe-haven investments," said Vinod Nair, head of research, Geojit Financial Services.