Mathews was 200 not out at the declaration and batted for exactly 10 hours over two days to take Sri Lanka well past Zimbabwe's first innings of 358 all out.
Zimbabwe was 30-0 in its second innings and still 127 behind at stumps on the fourth day.
Zimbabwe needs to bat solidly on the final day to have a chance at a draw in its first test in more than a year. Sri Lanka has hopes of applying pressure at Harare Sports Club to set up a victory.
The teams are playing two tests in the series.
Mathews wore down the bowlers with a mixture of solid defense and aggressive stroke-play. The 32-year-old right-hander faced 468 balls and cracked 16 fours and three sixes, sharing a 136-run partnership for the sixth wicket with Niroshan Dickwella (63).
"I had to work really hard, the Zimbabweans didn't give anything away," Mathews said. "They just bowled exactly the lines and the lengths required on these kind of wickets. They kept hitting the right areas and we had to work extremely hard. We had to grind and grind and grind and fortunately I was able to do that with the help of the other batters."
Dickwella departed when he was trapped lbw by off-spinner Sikandar Raza (3-62), who also removed Suranga Lakmal (27) and Lasith Embuldeniya for a duck.
"For a nation who hasn't played test cricket in 17, 18 months — and we've gone through a tough period — to be able to take the test to a fifth day, I think we're on the right direction," Raza said.
Debutant Zimbabwe pace bowler Victor Nyauchi ended with figures of 3-69 and also claimed the wicket of Dhananjaya de Silva for 63.
Sri Lanka was 295-4 overnight and had Kusal Mendis's 80 from the previous day as its second highest score of the innings.
Zimbabwe opening batsman Kevin Kasuza, who is playing his first test, has been replaced for the rest of the game after suffering a delayed concussion. Kasuza, who scored 63 in the first innings, was hit by the ball on the helmet while fielding close to the batsman at short leg on day three.
He was replaced by Brian Mudzinganyama under the International Cricket Council's new concussion rules.
Mudzinganyama was 15 not out opening the batting with Prince Masvaure in Zimbabwe's second innings. Masvaure, who scored a half century in the first innings, was unbeaten on 14 at the close of play.