Mathews was last man out for 122 as Sri Lanka took their overnight score of 228-5 to 313 before they were all out in their second innings at the stroke of lunch on the fourth day.
Fast bowler Imran Khan, operating with the second new ball, took all the five wickets that fell in the morning session in the space of 33 balls.
Imran's maiden five-wicket haul saw Sri Lanka lose their last five wickets for 35 runs after they were coasting at 278-5 in the first hour of play.
Mathews, who came in to bat on Sunday afternoon with his team reduced to 35-3, anchored the innings for more than six hours in which he hit 12 boundaries and a six.
Also Read
Mathews reached his fifth Test century with a flick off Rahat Ali for two runs, but not before he lost two partners off consecutive balls when he was on 99.
Dinesh Chandimal was trapped leg-before by Imran for 67, ending a 117-run partnership for the sixth wicket with Mathews.
Tharindu Kaushal denied Imran a hat-trick with a defensive push and then celebrated the achievement by flicking the same bowler for a boundary in his next over.
But Imran had Kaushal (eight), Suranga Lakmal (zero) and Mathews caught behind by Sarfraz to hasten the end of the innings.
Pakistan won the first Test in Galle by 10 wickets and Sri Lanka took the second in Colombo by seven wickets.