Gambhir followed his 92 in Sunday's win against Australia with another innings of substance, but it was Dhoni's peerless final touches which kept India alive.
Just as he did against the Australians, Dhoni combined with Gambhir in a crucial partnership - which netted 60 runs - until the skipper ran out his opener.
Gambhir's cruel end came when Dhoni pushed to mid on, called a single, then changed his mind - leaving Gambhir unsuccessfully scampering to make his ground.
The 41st over run out left India wobbling at 5-178, but Dhoni wasn't rattled.
He whittled down the equation to 24 runs from the last two overs, and nine from the last.
But crucially Dhoni was off strike for two of the final six balls.
Earlier, Sri Lanka's rising star Dinesh Chandimal top-scored with 81 in their middling total, with support from captain Mahela Jayawardene (43) and Kumar Sangakkara (31).
The 22-year-old Chandimal and his skipper featured in a 94-run partnership which rallied the Lankans after a sluggish start - they were 3-79 in the 20th over.
But both Chandimal, whose polished knock following returns of 37 and 64 in Sri Lanka's initial two losses of the series, and Jayawardene fell within seven costly balls.
Jayawardene was trapped lbw by Indian paceman Vinay Kumar, who impressed with 3-45 from 10 overs.
And Chandimal perished in the next over, run out to end his 91-ball innings.
Their dismissals were compounded when Thisara Perera (five) was out two overs later to the bowling of Ravi Ashwin (2-30 from 10 overs) as the Lankans lost 3-11 and all momentum, with their tailenders unable to finish with a run flourish.
The tie was marked by controversy, with India's batsmen facing one less delivery than they should have - the 30th over of their innings contained just five balls.
"I'm not complaining,'' said Sri Lankan captain Mahela Jayawardene.
Indian captain Dhoni was remarkably accepting of the mistake.
"There was a five ball over,'' he said.
"In the past what we have seen is the third umpire interferes and you have to come back and bowl that ball.
"Usually that is what has happened to us, it didn't happen in this game - it's fair enough, nothing much can be done now.''
- AP