In reply to New Zealand's first innings total of 249 all out, Sri Lanka were on 143 for two as Mathews and Mendis laid the foundation.
Galle: Left-arm spinner Ajaz Patel became the first New Zealander to claim a five-wicket haul in Galle as the tourists restricted Sri Lanka to 227 for seven at stumps on day two of the first Test on Thursday.
In reply to New Zealand's first innings total of 249 all out, Sri Lanka were on 143 for two as Angelo Mathews and Kusal Mendis laid the foundation for a big total.
However a lapse of concentration saw Mendis throw away his wicket in the penultimate ball before tea and they collapsed, losing five wickets for the addition of 18 runs.
From 143 for two, Sri Lanka slumped to 161 for seven before an unfinished 66-run stand for the eighth wicket between Niroshan Dickwella and Suranga Lakmal stopped the rot. Sri Lanka trail New Zealand by 22 runs.
It was the second five-wicket haul in Test cricket for Bombay-born Patel, who was tidy with his length on a track that offered lot of assistance for spinners.
Patel was not afraid to flight the ball even after Mendis completed his 10th Test half-century with a boundary off him.
For the next delivery, the penultimate ball before tea, Mendis attempted to play an expansive drive without much foot work and was caught at first slip by Ross Taylor.
The slide continued after tea with Kusal Perera (1) and Dhananjaya de Silva (5) adding to the misery.
Mathews was dismissed soon after completing his half-century, becoming Patel's fifth victim.
Then off-spinner William Somerville dismissed Akila Dananjaya for a sixth ball duck.
Lakmal, who had claimed four wickets earlier in the day, then gave solid support to Dickwella as Sri Lanka fought back. Lakmal was given out caught at slip when he was on nine but he successfully reviewed the decision.
There were some cheeky shots played by Dickwella, who is under pressure to save his place having been overlooked for the World Cup.
Lakmal's contributions were welcomed as well as Sri Lanka know that chasing anything above 150 on this track is dicey.
Resuming from the overnight score of 203 for five, New Zealand were knocked out for 249 losing their last five wickets for 46 runs.
Lakmal claimed the four wickets to fall on day two while Tim Southee was run out. Akila Dananjaya finished with five wickets, with all his wickets coming on day one.