The left-arm spinner first removed well-set Azhar Ali for 85, before dismissing tail-ender Yasir Shah (eight) off the last ball ahead of lunch to leave Pakistan at 340-8 at the interval.
Debutant Haris Sohail was unbeaten on 31.
Pakistan had resumed at a relatively promising 266-4, but at lunch still trailed Sri Lanka's first-innings total of 419 by 79 runs with only two wickets left.
It was Herath who gave his team the much-needed wicket of a resolute Ali, luring him into an uppish drive which was brilliantly caught at short mid-wicket by a diving Kusal Mendis.
Paceman Suranga Lakmal then came into his own, bowling Pakistan skipper Sarfraz Ahmed off an inside edge for 18 before trapping Mohammad Amir leg before for four.
Herath was the pick of the bowlers with 4-59 while Lakmal has figures of 2-41.
Disclaimer: No Business Standard Journalist was involved in creation of this content