Left-arm spinner Rangana Herath claimed a career-best 9-127, but Pakistan carried their overnight score of 244-6 to 332 before they were all out at the stroke of lunch on the third day at the Sinhalese Sports Club.
The tourists, seeking a series-levelling win after losing the first Test in Galle by seven wickets, will look to dismiss Sri Lanka cheaply on a wearing pitch that has begun to take slow turn.
Sarfraz, who came to bat after tea on Friday with Pakistan struggling at 140-5, scored a gutsy 103 to lead a remarkable fightback by the lower order.
Resuming on 66, Sarfraz reached his hundred by hooking left-arm seamer Chanaka Welegedara for a six after pulling the previous delivery for a boundary.
He was ninth out with Pakistan just six runs away from taking the lead when he edged Herath to give wicket-keeper Niroshan Dickwella his fifth catch in the innings.
Last man Junaid Khan hit an unbeaten 13 to help Pakistan go past Sri Lanka's total.
The 36-year-old Herath is the number one Test spinner in the official rankings. He has claimed 255 wickets so far in 57 Tests.
