And he was followed by fellow opener Arul Suppiah, who fell to the left-arm spin of Rangana Herath.
Zaheer then dismissed Rangana Herath (three) and overnight batsman Nuwan Kulasekara (19) to finish with figures of 5-72.
BBC: India beat Sri Lanka by an innings to top Test rankings
Amla was no slouch at the other end, showing excellent footwork to take on spinners Chandana and Rangana Herath.
Herath finished with figures of five for 121 from 33 overs, while Mendis claimed two for 162 from 38.
Herath is likely to partner Mutthiah Muralitharan, whose eight wickets in Colombo took his overall Test tally to 261.
At 225-8, Hampshire were struggling, but crucial support from Rangana Herath enabled McKenzie to drag the visitors over the finishing line.
In a gripping finish, the former international timed the run-chase to perfection in a run-a-ball ninth-wicket stand of 56 with Herath, who finished 10 not out.
Dravid, 36, made a superb 144 before India succumbed to spinner Rangana Herath's five wickets, all out for 642 when a score over 700 seemed certain.
Dravid eventually fell just before lunch when left-armer Herath palmed a shot from Laxman onto the stumps at the non-striker's end and caught Dravid backing up too far.
Dhoni dominated the last session with a stunning century, during which he struck six sixes, one of which - a straight drive off Herath - brought up his hundred.
Sri Lanka are to strengthen their spin attack with the inclusion of left-armer Rangana Herath in the squad for the second Test against Pakistan, which starts in Galle on Wednesday.
Ervine brought up his century off 169 balls, including 15 fours and a six, and, after sharing 48 for the eighth wicket with Herath, saw the hosts to 392-8 at lunch.
But with Herath gritting it out at the other end, McKenzie took charge, dominating the strike and hitting two sixes over square leg off Adams, before a third sealed the match.
Murali Vijay was given a rare Test appearance with Gautam Gambhir away at his sister's wedding and responded with a contribution of 87 in a 221-run opening stand before falling lbw on the sweep to Rangana Herath.
BBC: Virender Sehwag blitzes Sri Lanka as India pile on runs
The spinners kept up the pressure by choking boundaries, but half-brothers Darren and Dwayne Bravo tried to break the shackles by hitting a six each off consecutive Herath overs as the 150 came up in the 31st over.
应用推荐