They had resumed at 3-20, needing another 276 runs to even make New Zealand bat again, after Tom Latham’s maiden double century of 264 not out had powered the hosts to a massive first innings total of 578.
They frustrated New Zealand’s bowlers, who resorted to a short-pitched attack early on, changed to a fuller length towards lunch, then virtually shut down the scoring during the middle session with Ajaz Patel shoring up one end.
Nothing, however, worked against Mendis and Mathews, who were untroubled on a pitch offering little in the way of sideways seam movement, although left-arm spinner Patel got the occasional delivery to bite and bounce.
Mendis was the more fluent with some memorable drives down the ground before he brought up his sixth Test century shortly after tea when he pulled a short delivery from Neil Wagner fine for his 12th boundary.
Mathews achieved his ninth century about an hour before stumps when he drove Colin de Grandhomme through midwicket for his 11th boundary.
He then proceeded to do some push-ups mid-pitch – a potential riposte at the selectors who dropped him in September from the one-day squad for fitness reasons.
It was the third successive innings in New Zealand that Mathews has resurrected his side’s fortunes when staring at embarrassment.
The 31-year-old top-scored with 83 in Sri Lanka’s first innings of 282 and combined with Dimuth Karunaratne for a 133-run partnership after they slumped to 3-9 inside the first four overs.
That innings followed on from his score of 128 not out in Sri Lanka’s only warm-up game against an inexperienced New Zealand selection in Napier, when they had slumped to 9-104 before he pushed them to 210 for nine declared.