Chasing a revised target of 187 from a maximum 21 overs, Afghanistan slumped from 34-0 to 57-5 then battled back through a 64-run stand between Gulbadin Naib (23) and Najibullah Zadran (43).
Sri Lanka again responded and took the final five wickets for 31 runs, with recalled seamer Nuwan Pradeep getting 4-31.
The 1996 World Cup winner lost its opening group game to New Zealand by 10 wickets. Afghanistan has two defeats from two matches, after a loss to Australia on Saturday.
The error-strewn match in Cardiff featured 52 extras - Sri Lanka's 35 was the second-highest scorer in the scorecard - to strengthen the feeling this was a contest between the two teams likely fighting to avoid last place in the 10-team group.
The Afghans' only win at a World Cup remains the one over Scotland in 2015 but they'll feel this match slipped from their grasp, especially when Sri Lanka was reeling at 159-6 after three wickets in one over from Mohammad Nabi.
Sri Lanka, which made the fastest 10-over start to the tournament by racing to 79-0, lost its last nine wickets for 57 runs in 15.4 overs.