The total was considered challenging on a dry, used Headingley pitch. And India had failed in three of its last four chases.
But thanks to Sharma and Rahul, who blasted 25 boundaries and three sixes between them, India knocked off the winning runs with 39 balls to spare.
Already through to the semifinals, India needed to beat Sri Lanka and hope Australia loses to South Africa in their ongoing match, to finish top of the standings. If the standings hold, India will play New Zealand in the first semifinal on Tuesday in nearby Manchester.
Sharma and Rahul wasted no time. They reached 50 together in 41 balls, India's fastest of the tournament. They have averaged 72 in five previous opening stands, and blew past that in the 13th over.
They reached 100 in the 19th over, and slowed down somewhat in the face of spin. But not for long.Rahul woke up the crowd with 4-6-0-4 off Dhananjaya de Silva in the 23rd over.
Sharma brought up his third consecutive century — matched only by Virat Kohli — with a pull of a Kasun Rajitha delivery to the square leg boundary, his 14th four.
Rajitha got him in his next over, spooning straight to the mid-off fielder on 103 off 94 balls.
At this World Cup, Sharma has hit 122 not out against South Africa, 140 against Pakistan, 102 against England, and 104 against Bangladesh.
Rahul's form had been promising a big score since he'd stepped into the opener's role after Shikhar Dhawan was sidelined by injury. He finally went on and got there in the 39th over. His hundred came from 109 balls.
He was out with victory almost in India's grasp, gloving an edge behind. His wicket gave Lasith Malinga his 56th in World Cups, and outright third on the tournament all-time list.
Malinga, likely playing his last World Cup match, was obviously chuffed.
For Sri Lanka, Angelo Mathews led with 113, in the middle when Sri Lanka was reduced to 55-4 within 12 overs.
Jasprit Bumrah removed the openers to give him his 100th and 101st ODI wickets, and wicketkeeper MS Dhoni was involved in all four wickets with three catches and a stumping.
Mathews and Lahiru Thirimanne were slow but steadfast as they pulled Sri Lanka out of deep trouble.
They hit only one boundary in 14 overs. They were just starting to push the run rate when Thirimanne was out for 53.
Mathews was defiant. He was dropped on 61 then hit the sightscreen with his first six of the match, and when he survived a stumping chance he hit his second six in the same over.
Possibly his last World Cup bat ended in the 49th over, and de Silva got Sri Lanka to the end with an unbeaten 29.
- AP