Chasing 276 for victory, India found themselves in trouble after they lost Prithvi Shaw, Ishan Kishan and skipper Shikhar Dhawan cheaply to leave the tourists struggling at 65-3.
Sri Lankan spinner Wanindu Hasaranga picked up three wickets, including the two openers, but India's tail wagged at the death to deny Sri Lanka victory, overhauling the target with five balls to spare.
Yadav rallied India with some sublime strokeplay to reach his fifty before he was eventually dismissed for 53, trapped leg before by Lakshan Sandakan with 116 runs required to win.
Hasaranga also removed Krunal Pandya, who was looking dangerous with a handy knock of 35 before he was bowled but Chahar dug his heels in with an unbeaten 69, supported at the other end by vice-captain Bhuvneshwar Kumar (19 not out).
Earlier, a fighting 65 off 68 balls from middle order batsman Charith Asalanka propelled Sri Lanka to 275-9 in 50 overs.
Asalanka walked in to bat with Sri Lanka 124-3 and he held the innings together with Chamika Karunaratne, who remained unbeaten with a quick-fire 44 off 33 balls.
Opting to bat after winning the toss, the hosts got off to a slow but steady start, with Avishka Fernando (50) and Minod Bhanuka (36) constructing a 77-run opening stand.
But both fell in quick succession as the Indian attack made the most of a slow wicket where runs were hard to come by.
Leg-spinner Yuzvendra Chahal was the pick of the Indian bowlers, finishing with figures of 3-50 from his 10 overs while Bhuvneshwar (3-54) picked up the crucial wickets of half-centurions Fernando and Asalanka.
The series decider will be played at the same venue on Friday. With regular captain Virat Kohli and several frontline players in England for a five-test series, India sent a second string side with Rahul Dravid as coach.