IT stocks, Infosys, TCS and Wipro were in demand as the rupee weakened against the dollar.
Despite today's gain, the 30-share index posted its first weekly loss in three weeks with a fall of 355 points or 1.35 per cent. Besides, Nifty fell by 113 points or 1.42 per cent.
Market will be closed tomorrow on account of Eid.
Gains were tempered by lower US futures ahead of the Federal Reserve Chair Janet Yellen speech later in the day.
More From This Section
"... Adding to this, market is also cautious ahead of the RBI policy event on September 29," added Nair.
Sentiment improved following a mild uptick in rollover of futures and options contracts to October.
After resuming lower at 25,798.05, the Sensex hovered in a range of 25,949.90 and 25,670.96 before closing at 25,863.50, showing a gain of 40.51 points or 0.16 per cent.
The broader Nifty ended up by 22.55 points or 0.29 per cent at 7,868.50 after trading between 7,804.10 and 7,894.50.
Those who gained included Lupin, GAIL, ITC, Bajaj Auto and Maruti Suzuki.
According to Jayant Manglik President Retail Distribution at Religare Securities, it was the stock specific move which kept the traders busy till the end.
Most sectoral indices closed flat to marginally in red barring IT and FMCG, he added.
Asian markets ended mixed following overnight fall in US. Key indices in Japan, Hong Kong and Taiwan dropped by 0.86 per cent to 2.76 per cent, while indices in China and South Korea moved up by 0.13 per cent to 0.86 per cent.