A fall in Brent crude prices to 16-month lows and recent supportive economic data at home such as better-than-expected 5.7% GDP growth in the April-June quarter are also reinforcing investor optimism.
The gains also tracked a rise in global stocks after Ukraine said it reached a ceasefire agreement with Russia, despite conflicting reports from the Kremlin. Overseas investors continued to buy stocks ahead of a crucial European Central Bank meeting on Thursday, which is widely expected to provide further stimulus for revival, thereby aiding liquidity in the financial markets.
Foreign portfolio investors bought shares worth Rs 673 crore ($111 million) on Tuesday, taking their total purchase to over $13 billion so far this year.
"Political and economic changes have led to a positive trend in the equities which should continue. Also, India stands out in the world due to its strong domestic growth story," said Nirakar Pradhan, chief investment officer at Future Generali India Life Insurance.
The Sensex touched its fourth consecutive record high of 27,225.85, before ending 0.45% higher at 27139.94.
The Nifty rose as much as 0.73% to mark its third straight record high at 8,141.90. It closed up 0.39% at 8114.60.
Software stocks gained after data showed US manufacturing activity hitting a nearly three-and-a-half-year high last month and construction spending rebounding strongly in July, providing signs the economy entered the third quarter on a strong footing.
Infosys gained 3.3%, Tata Consultancy Services ended up 2.7%, Wipro rose 2.9%, while Tech Mahindra advanced 1.5%.
Meanwhile, oil retailers gained after Brent crude slumped to 16-month low on Tuesday. Prices rebounded on Wednesday but ample supplies and lingering demand worries limited the rally. Hindustan Petroleum Corp gained 1.3 %, Indian Oil Corp rose 1.6%, while Bharat Petroleum Corp ended 0.13% higher. Carborundum Universal ended 2.6% higher after earlier marking a record high of Rs 217.35 as HDFC Mutual Fund raised stake in the abrasives maker to 4.61% from 4.08%, via a block deal on Tuesday.
Tata Motors gained as much as 2.8 % after a slew of rating upgrades, citing valuations and improving outlook for its luxury car making unit Jaguar Land Rover. Among the stocks that fell, Cipla lost 0.7% after surging to a record high of Rs 575 on Tuesday.