India's Shikhar Dhawan plays a shot for four runs.─ AFP
But Sri Lanka defied the odds to win with eight balls to spare and they can qualify for the semi-finals if they beat Pakistan in their final group match in Cardiff on June 12.
After losing by 99 runs against South Africa in their opener, that would be a remarkable turnaround for a young Sri Lanka team in the midst of a major rebuilding project.
India's failure to secure a second consecutive win after thumping arch rivals Pakistan was a major surprise and they must beat South Africa at The Oval on Sunday to avoid a humiliating exit.
Shikhar Dhawan's 125 had put India in a strong position as the holders piled up 321 for six.The 31-year-old hit 15 fours and one six in his 128-ball innings, receiving strong support from Rohit Sharma (78) and MS Dhoni (63), but it wasn't enough.
India had only themselves to blame after squandering the momentum given to them by Bhuvneshwar Kumar, who dismissed Niroshan Dickwella for seven when the opener's edge was caught by Ravindra Jadeja.
Needing what would be a record run chase in ODIs staged at The Oval, Gunathilaka set about giving Sri Lanka hope.
He hit Umesh Yadav for a sky-scraping six and, together with the aggressive Mendis, imposed himself well enough to build a quick-fire 50 partnership.
Hardik Pandya had a chance to remove Mendis with the score on 70-1, but the young all-rounder dropped a chance off his own bowling.
Audacious
If complacency was an issue for India's wayward bowlers, Gunathilaka made them pay, reaching his half-century in emphatic style with another six.
By the time Sri Lanka reached 108-1 in the 20th over, the holders were beginning to worry.
Jadeja, the world's top ranked ODI bowler, was slapped away for four by Mendis, who sailed onto fifty with his first six.
An audacious reverse sweep for four by Gunathilaka off Jadeja showed Sri Lanka's rising confidence, which hold spiked higher after the diving Rohit Sharma dropped Gunathilaka.
When Mendis hit three successive boundaries, their partnership was up to 159 and India were in danger of letting the match slip from their grasp.
But Gunathilaka's career-best ODI innings came to an end when he was run out by Umesh Yadav after rashly trying to turn a single into two.
Incredibly, Sri Lanka didn't learn from that mistake and Mendis perished in the same fashion, easily run out by Kumar's direct hit while attempting to steal a single.
Crucially, Mathews, playing his first ODI since August after a calf injury, came in to steady the ship with a nerveless innings.
Assisted by the opportunistic hitting of Kusal Perera, he turned the tide back in his team's favour.Perera gave Sri Lanka a scare when he suffered what appeared to be a hamstring injury and had to retire hurt after limping through several runs.
That added to the tension, but India were bereft of ideas.
Gunaratne came in to spank a pair of sixes, putting Sri Lanka on the brink, and Mathews saw them over the finish line to complete their joint highest ever ODI run chase.
Teams
India: Rohit Sharma, Shikhar Darwan, Virat Kohli (captain), Yuvraj Singh, Mahendra Singh Dhoni, Kedar Jadhav, Hardik Pandya, Ravindra Jadeja, Bhuvneshwar Kumar, Umesh Yadav, Jasprit Bumrah.
Sri Lanka: Niroshan Dickwella, Danushka Gunathilaka, Kusal Mendis, Dinesh Chandiwal, Angelo Mathews (captain), Kusal Perera, Asela Gunaratne, Thisara Perera, Suranga Lakmla, Lasith Malinga, Nuwan Pradeep.