Herath, who took nine for 127 in the first innings, had figures of four for 46 in the second as Pakistan finished day four on 127 for seven, still way short of their target of 271.

Sri Lanka began the day on 177 for two with the match still in the balance, and although wickets came in bundles in the morning, they added another 105 runs to build a decent lead.

Saeed Ajmal got Kumar Sangakkara early for 59 and his overnight partner Mahela Jayawardene swiftly followed for 54, leaving them on 189 for four.

Angelo Mathews came in and would remain until the end to make 43 not out, but few of his partners stuck around - Niroshan Dickwella the best of them with 21.

Saeed Ajmal (three for 89) added his third wicket when Lahiru Thirimanne was bowled for 10, while Wahab Riaz (three for 76) helped him mop up the tail end with three late wickets of his own as Sri Lanka were bowled out for 282.

However, Pakistan's reply never gained much momentum.

Seventeen runs were on the board when Khurram Manzoor was caught behind for 10, and fellow opener Ahmed Shehzad soon gave Dhammika Prasad his second wicket, gone lbw for eight.

The partnership between Asad Shafiq and Sarfraz Ahmed steadied the ship, adding 55 before Shafiq was stumped when coming to meet a Herath delivery.

There was still time for Dilruwan Perera to trap Abdur Rehman lbw for five, and although Ahmed remained on 38 unbeaten at the close, there was little reason for optimism in the Pakistan dressing room come stumps.