Muralitharan had needed eight wickets from the match to reach 800 in his career and had managed five in the first innings.
But as India doggedly fought their way to 338 runs, it seemed as though he might miss out on the milestone until Ojha was brilliantly caught at first slip by Mahela Jayawardene.
India resumed the final day on 181-5 after being forced to follow on, but was hopeful that its last recognised batting pair would rescue them from defeat.
However, seamer Lasith Malinga struck after just five runs had been added to the overnight total, bowling Indian captain Mahendra Singh Dhoni with a yorker.
Muralitharan then trapped Harbhajan Singh lbw to record his 799th wicket, but as Sri Lanka focused on Muralitharan’s record, India’s tailenders and V.V.S. Laxman ate up some valuable time and added crucial runs.
Laxman who looked solid against an aggressive bowling attack was eventually run out for 69 after lunch. He faced 127 balls and hit five boundaries.
Earlier, Sri Lanka’s President Mahinda Rajapaksa flew in by helicopter to watch a few minutes play and spoke to Muralitharan, who is retiring.