Mystery spinner Hasaranga (3/13) and pacer Lahiru Kumara (2/30) shared five wickets among themselves to restrict Afghanistan to 144 for 8.
Dhananjaya then took control of the Sri Lankan innings with a strokeful unbeaten 66 off 42 balls as the reigning Asia Cup champions crossed the line with nine balls to spare.
With the win, Sri Lanka climb up to the third spot in group 1. Afghanistan, on the other hand, dropped out of semifinal contention.
Defending a modest total, Sri Lanka started off well but Mujeeb ur Rahman (2/24) produced a leading edge to mark the end of Pathum Nissanka (10) putting the Sri Lankans under pressure.
Fazalhaq Farooqi (1/22) bowled a maiden in the following over to tighten the screws. However, Kusal Mendis (25) hit back-to-back boundaries in the next over, both over midwicket as Sri Lanka dallied to 28 for 1 in the Powerplay.
Rashid Khan (2/31) struck in his first over as Mendis went for a premeditated sweep but top-edged for the keeper to catch it.
While the Afghans tried to build pressure by bowling dots, Sri Lanka continued to score at a healthy rate, milking boundaries and sixes every now and then.
Rashid’s second over went for 14 runs as de Silva hit a four down fine leg before slogsweeping the star spinner over deep mid-wicket for a six. Dhananjaya continued the onslaught with a six off Mohammad Nabi in the next over to keep the required run rate within seven.
Together with Charith Asalanka (19), Dhananjaya stitched a 54-run stand followed by a 42-run partnership with Bhanuka Rajapaksa (18) to take Sri Lanka to victory.
Earlier, while the Afghans were able to stitch a few partnerships at the top, Sri Lanka did well to strike at regular intervals. The ball swung in the opening two overs but after that the Sri Lankan bowlers struggled to get their lengths right as Rahmanullah Gurbaz (28) donned the role of the aggressor.
The wicketkeeper batter danced down and hit a glorious straight drive off Kasun Rajitha to register the first maximum of the innings. The Afghans then hit three more fours and a six to collect 42 off the first six overs.
However right after the powerplay, Kumara fashioned the first breakthrough for the Sri Lankans. Gurbaz looked to go big but there was just enough movement as the ball traversed the gap between the bat and pad to crash into the stumps.
The spinners were then able to slow down the proceedings after the wicket but Usman Ghani (27) whacked Kumara for a six to long off. Looking to up the ante, Ghani once again tried to go for it in the 11th over off Hasaranga, who was brought back into the attack.
However, the Afghan was was done by a googly that had a touch of bounce on it and skipper Dasun Shanaka pouched it at deep mid wicket. Ibrahim Zadran (22) became Kumara’s second victim in the 13th over.
With wickets in hand, Mohammad Nabi (13) dispatched a slower one to extra-cover. But the skipper wasn’t able to stay in the middle for long as Afghanistan failed to fire in the death overs, losing five wickets for 40 runs off the last 30 balls. Sri Lanka were once against guilty of being sloppy on the field.