Sarfraz's maiden Test century enabled Pakistan take their overnight score of 244-6 to 332 before they were all out at the stroke of lunch on the third day.
Sri Lanka, who won the first Test in Galle, had scored 320 in their first innings.
Herath finished with nine for 127, surpassing his previous best of 7-89 against Bangladesh in Colombo last year.