Title-holders Sri Lanka outlasted a rampaging Afghanistan by just two runs in a dramatic finish to reach the Asia Cup Super Four stage on Tuesday.
Needing to overhaul a target of 292 in 37.1 overs to oust Sri Lanka on net run-rate, Afghanistan fell agonisingly short as Mujeeb Ur Rahman holed out with three needed from the first ball of the 38th over.
They could still have qualified by reaching 295 within 37.4 overs but appeared to not be aware of that permutation as number 11 Fazalhaq Farooqi blocked out two deliveries before being dismissed while attempting another defensive shot with six needed to go through.
Mohammad Nabi hit a blistering 32-ball 65 while skipper Hashmatullah Shahidi made a 66-ball 59.
Rashid Khan hit three boundaries off Dunith Wellalage's 37th over, but off the first ball of the next over Mujeeb was caught on the boundary.
Sri Lanka were earlier guided to 291-8 by Kusal Mendis who scored a brilliant 84-ball 92.
Pakistan and India had already qualified for the Super Four stage from Group A, with Sri Lanka and Bangladesh joining them from Group B.
Pakistan face Bangladesh in Lahore on Wednesday to start the Super Four stage.
Afghanistan were struggling in the 20th over on 129-4 but Nabi started to hit out and the situation changed as they added 96 in the next 10 overs.
Nabi, who put on 80 for the fifth wicket with Shahidi, cracked five sixes and six fours to help Afghanistan get back on track, hitting the fastest ODI half-century for his country off just 24 balls.
Mujeeb had set the previous record against Pakistan in Sri Lanka last month off 26 deliveries.
Nabi holed out off Maheesh Theekshana in the 27th over but Shahidi and Karim Janat (22) kept up the tempo, adding 33 before they both fell in the same over from Wellalage.
Despite the double blow, Afghanistan did not give up as Najibullah Zadran (23) and Rashid (27 not out) kept them in contention.
But in a dramatic finish, the Afghan camp did not realise their hopes were still alive once Mujeeb was dismissed and Sri Lanka progressed.
Sri Lankan skipper Dasun Shanaka admitted Nabi nearly took away the game.
"It's a tough one," said Shanaka whose team has now won 12 consecutive ODIs. "The first target was a 37.1-over game and Nabi almost took the game away from us but we got wickets when needed."
Shahidi said: "It's very disappointing to lose. We fought well and gave our best I am proud of the team, the way they played, and fought till the last ball."
Earlier, the 28-year-old Mendis played an attractive innings that included three sixes and six fours to anchor the Sri Lankan innings after they won the toss and batted first.
Sri Lanka got off to a solid start of 63 for the first wicket between Pathum Nissanka (41) and Dimuth Karunaratne (32).
Mendis took over and added 102 for the fourth wicket with Charith Asalanka, who made a 43-ball 36.
But from 186-3 Sri Lanka had a middle-order stutter that saw them lose four wickets in the space of 41 runs, including that of Mendis who was unluckily run out.
Rashid dropped a drive from Shanaka onto the stumps with Mendis short of his ground at the non-striker's end.
Wellalage, who scored an unbeaten 33, added an invaluable 64 runs for the eighth wicket with Theekshana (28).
Gulbadin Naib dismissed Theekshana off the final delivery to finish with Afghanistan's best figures of the innings with 4-60.