Sri Lanka started the day at 20 for 3 hoping to save the Test.
Mendis and Mathews played out the whole first session, and scored 102 runs to take the team to 122 for 3.
Wagner was poor in the first session and leaked 36 runs from his first five overs.
After playing out the whole second session, Mendis registered his sixth Test ton early in the final session.
Mathews too made a statement with a century and stayed unbeaten on 117.
Mathews and Mendis scored unbeaten 246 for the for the fourth wicket. They played out the whole day to lift Sri Lanka to 259 for 3 and now trail by just 37.