Skipper Sarfraz Ahmed shared an innings-reviving 42-run stand with Haris Sohail but when he was stumped, advancing down the wicket to Herath, Pakistan slumped to 78-6 and Sri Lanka had the upper hand.
Herath became the 14th bowler in all Test cricket and the fifth spinner behind his fellow countryman Muttiah Muralitharan, Australia's Shane Warne and India duo Anil Kumble and Harbhajan Singh to reach the 400-wicket milestone.
From Sri Lanka, Rangana Herath bagged 6 wickets while Dilruwan Perera took 3.
Even after taking a 3 runs lead, though it was the smallest lead having been taken Pakistan in Tests while batting second, and bowling Sri Lanka out for 138 runs, Pakistan's batting once again struggled and was all out for 114 runs. Bat continued to dominate ball in Pakistan's reply, with the top three batsmen posting half centuries and Sohail adding his valuable 76 to give his team a three-run first-innings margin.
Pakistan were 121-2 at lunch and went through the afternoon session without conceding a wicket to go to tea at 194-2.
Niroshan Dickwella remained defiant, however, and when Pakistan's batsmen then hit nearly immediate trouble it became clear the Sri Lanka wicketkeeper's unbeaten 40 could well be significant. Herath now has 400 wickets to his name from 84 Test matches.
Meanwhile, medium pacer Mohammad Abbas claimed two wickets of Kusal Mendis and Suranga Lakmal.
The defeat was the first Pakistan have suffered at the venue in the UAE which has served as the nation's home base for the last few years. Mohammad Abbas was the pick of the bowlers with three for 75. With this Pakistan need 136 runs to win the match. "The only thing I can say, it's not a mitigating excuse at all, but that's a young batting line up, obviously trying to find their way", said Mickey Arthur, Pakistan's coach. It's hard in the middle, Dickwella and Karunaratne were very good in the first innings, Dickwella was unbelievable in the second innings to get us to the 140-run mark. There are some batting issues in our team and we were put under pressure. The technology returned a verdict of "umpire's call", which no longer sees the unsuccessful team lose one of their two reviews per innings.
"Looking to the future, yes, he is 39, a little bit old now, but he always tries to do his best". Needed one partnership and the game was ours. As soon as we got there, we knew Rangana would lead us in the defence of the target.