India avoided a huge World Cup upset with Mohammed Shami's last-over hat-trick earning an 11-run victory over Afghanistan in an absorbing, low-scoring game at The Hampshire Bowl.
Afghanistan, who restricted India to 224-8, required 16 from the 50th over with three wickets in hand after Mohammad Nabi (52 off 55) had kept their chase alive with a superb innings in Southampton.
However, Shami (4-40), who was blazed for four by Nabi from the first ball of the over, then had the batsman caught from the third delivery before bowling Aftab Alam and Mujeeb Ur Rahman for golden ducks to deny Afghanistan a famous win and keep India unbeaten.
Jasprit Bumrah (2-39), who shipped just five runs from the penultimate over, had seemingly wrecked Afghanistan's hopes when he removed Rahmat Shah (36) and Hashmatullah Shahidi (21) in the 29th over as Gulbadin Naib's side slipped to 106-4, only for Nabi's admirable knock to give the 1983 and 2011 champions an almighty scare.
India had been limited by an Afghanistan attack thumped for 397 by England at Old Trafford four days earlier, with Mujeeb (1-26), Rashid Khan (1-38) and Nabi (2-33) suffocating Virat Kohli's men with spin - Kolhi (67) and Kedar Jadhav (52) the only players to pass fifty.
But their death bowlers then came up trumps as they consolidated their place in the top four - moving above England into third - and earned a 50th win at the World Cup.
Afghanistan were consigned to their sixth straight defeat, but will have won many admirers after subduing an India batting line-up that eased past 300 against Australia and Pakistan, and then taking the run chase to the wire.
India knew they were in a game when Rohit, who stroked a superb 140 against Pakistan at Old Trafford last Sunday, was bowled by Mujeeb for one in the fifth over with just seven runs on the board.
Kohli rallied India as he skipped to a classy 48-ball fifty, his third in a row after scoring 82 against Australia and 77 against Pakistan, and shared half-century stands with KL Rahul (30) and Vijay Shankar (29).
India's fans were stunned when Kohli cut Nabi to point in the 31st over to leave his side on 135-4 and they were unable to accelerate, hitting just seven boundaries from that stage.
MS Dhoni mustered a slow-go 28 from 52 balls during a timid-paced fifty partnership with Jadhav before he was stumped for just the second time in his ODI career, while Afghanistan picked up three wickets in the final two overs, with Gulbadin (2-51) dismissing Jadhav from the penultimate ball.
Kohli vented his frustration when a review to have Hazratullah Zazai pinned lbw by Shami went against his side early in the chase - the ball shown to have pitched marginally outside leg stump - and was visibly delighted when Shami bowled the same batsman four overs later for 10.
The India captain would have been fretting as first Gulbadin (27) and then Rahmat and Hashmatullah dug in, so he turned back to Bumrah and his seamer did not disappoint, forcing Rahmat to top-edge a pull to fine leg, before Hashmatullah ballooned a ball back to him two deliveries later.
Leg-spinner Yuzvendra Chahal (2-36) then castled Asghar Afghan (8) as Afghanistan sunk to 130-5, but Nabi, who was supported by Najibullah Zadran (21) and Rashid (14), kept his side believing, even more so when he successfully overturned an lbw dismissal against Shami in the 48th over with the ball shown to have struck him outside the line.
However, Bumrah's five-run penultimate over gave Shami plenty of runs to play with and, despite being belted for a first-ball boundary, he sealed a tense victory in thrilling style with the 10th hat-trick in World Cup history.
Watch every match of the ICC Cricket World Cup live on Sky Sports Cricket World Cup, including Pakistan vs South Africa from 10am on Sunday.