India chased down their target of 276 with five balls to spare as Chahar and Bhuvneshwar Kumar, who made 19, put on an unbeaten stand of 84 for the eighth wicket after the tourists had slipped to 193-7 in Colombo.
Chahar, who also took two wickets with his pace bowling to limit Sri Lanka to 275-9, recorded his maiden ODI fifty as India took an unbeatable 2-0 lead in the three-match series.
“These sort of matches we’re gonna learn a lot as a team and they’ll (players) learn how to handle games like these,” skipper Shikhar Dhawan said after the win.
“Everyone showed character. We knew that Chahar has worked hard in the nets on his batting. His presence of mind and calculations against the leg-spinner was amazing. Both Bhuvi and him calculated it really well.”
Leg-spinner Wanindu Hasaranga took three key Indian wickets but Suryakumar Yadav, who made 53, and Krunal Pandya, who scored 35, put up a fight until their departure.
Coming in to bat at number eight, Chahar turned the match on its head as he hit seven fours including the winning boundary and one six in his 82-ball knock.
Hasaranga struck early as he bowled Prithvi Shaw for 13 in his first over — third of the innings — and later trapped Dhawan lbw, a decision given not out by the umpire but successfully reviewed by Sri Lanka.
Yadav, an Indian Premier League star who made his ODI debut in the previous match, put on two partnerships including a 44-run sixth-wicket stand with Pandya.
He raised his maiden fifty off Lakshan Sandakan but fell lbw to the left-arm wrist spinner five balls later.
Hasaranga bowled Pandya for 35 to raise hopes of a Sri Lankan victory but Chahar, whose previous best was 12, put up his career-best show with the bat.
Earlier, number eight Chamika Karunaratne hit an unbeaten 44 to steer Sri Lanka to 275 for nine after crucial knocks from Avishka Fernando (50) and Charith Asalanka (65).
Kumar and Yuzvendra Chahal claimed three wickets each.
Fernando got Sri Lanka off to a strong start with a 70-run opening stand with wicketkeeper-batsman Minod Bhanuka, who made 36.
Chahal broke through with two successive strikes, sending back Bhanuka and Bhanuka Rajapaksa for nought.
Fernando kept up the fight with his fourth ODI half-century and put on 47 runs with Dhananjaya de Silva for the third wicket. But the opener soon fell to Kumar after his 50 off 71 balls.
Bowlers struck back with middle-order wickets, and although the left-handed Asalanka took the attack to the opposition with a maiden ODI fifty the effort was not enough for a win.
“We thought we put up a good total, but we lost the plot along the way,” Asalanka said.
“Sri Lanka’s young team was emotional after losing the series, but hopeful of bouncing back.”
The final match is on Friday at the same venue.