Till yesterday evening, the match was heading for a tame draw with Sri Lanka comfotably placed at 235 for five in their first innings in reply to India's 503 for seven declared.
Resuming their innings, Sri Lanka needed another 119 runs to reach 354 and avoid the follow-on.
But Indian pace duo of Atul Singh (3/39) and Chama Milind (2/41) had other plans as the Lankans lost their last five wickets for just 21 runs to enforce the follow-on on the home team.
Singh (2/38), Milind (2/46), Kuldeep Yadav (2/100) and Shreyas Iyer (2/22) shared eight wickets between them to bring India within sniffing distance of a win, which was not to be.
More From This Section
With Sri Lanka down at 241 for nine, still needing six more runs to avoid an innings defeat, the last-wicket pair of Mendis and Jayasinghe bat out 55 balls to save the match, much to the frustration of the Indians.
Sadeera Samarawickrama (88) top-scored for the Lankans in their second innings score of 264 for nine. Thilaksha Sumanasiri (62) also scored a half-century for the hosts.
The second and final Test of the series will be played in Welagedara Stadium, Kurunegala from July 29 to August 1.
Brief Scores:
India 1st innings: 503 for seven decl in 127 overs
Sri Lanka: 256 and 264 for nine in 92 overs (Sadeera Samarawickrama 88, Thilaksha Sumanasiri 62; Shreyas Iyer 2/22).