The hosts were leading by 89 runs in Colombo after elegant stroke play by the two experienced batsmen with Afghanistan unable to find a wicket in the second section.
Mathews (79) brought up his 41st half-century in Test cricket with a single off Zia-ur-Rehman while Chandimal (68) hit the milestone with a boundary that brought their partnership past 100 runs.
The wicket had flattened out after lunch and left the Afghan spinners unable to capitalise.
Afghanistan took three wickets before lunch on the second day after Sri Lanka resumed on 80 without loss.
Nishan Madushka was the first to depart for 37 after hitting straight to Noor Ali Zadran at leg-slip off debutant Naveed Zadran.
Kusal Mendis made 10 before misjudging a pull shot off a bouncer from Nijat Masood to be caught by Zia-ur-Rehman at square leg.
Veteran opener Dimuth Karunaratne posted his 35th Test half-century in an aggressive knock that saw 12 boundaries off 72 balls.
But the left-hander’s attempt to put away a full toss from Qais Ahmad saw him caught at short mid-wicket by Ibrahim Zadran for 77.
Afghanistan were bowled out for 198 in the final session of Friday’s first day, after being put in to bat by the hosts.