Mathews fell during tea, making 64, but De Silva went on to build another 50+ partnership with Sadira Samarawickrama, who made 36 before Aga Salman removed him with his last delivery of the day.
Earlier, Afridi made an impressive return to Test cricket after Sri Lanka opted to bat at a ground where they have played six of the last eight Tests, winning four of them.
Afridi suffered a hamstring injury at the same stadium last year and the left-arm fast bowler did not have to wait long to record his 100th Test wicket. Afridi reached that mark in the second innings, inducing a thick edge from opener Nishan Madushka, who took four hits and Sarfaraz Ahmed caught the ball behind off stump.
Rain interrupted play after 5.5 overs but on resumption, Afridi destroyed Sri Lanka’s top order with Kusal Mendis (12) perishing in the slip and Karunaratne (29) trapped.
Nasim Shah removed Dinesh Chandimal, who made one ball before Mathews and de Silva rescued Sri Lanka.
Abrar Ahmed removed Mathews with his last delivery before the tea break but de Silva, who made three sixes and 10 fours in his stellar knock, stayed on course for his tenth Test hundred.