ABU DHABI, United Arab Emirates (AP) — Sri Lanka suffered a narrow two-wicket defeat as seamer Faheem Ashraf (3-16) became the first Pakistani to achieve a hat trick in a Twenty20 international on Friday.

Pakistan, which whitewashed Sri Lanka 5-0 in the ODI series, took an unassailable 2-0 lead in the three-match T20 series with the last match scheduled to be played at Lahore on Sunday.

In yet another familiar batting collapse, Sri Lanka lost eight wickets in the last four overs and was restricted to 124-9 after being sent into bat.

But Sri Lanka new captain Thisara Perera (3-24) brought his team back into contention before Shadab Khan (16 not out) hit a vital straight six in the last over and took Pakistan to 125-8 with a ball to spare.

Opening batsman Danushka Gunathilaka (51) hit his maiden T20 half century and Sadeera Samarawickrama scored 32 off 31 balls to provide Sri Lanka with an ideal launching pad to accelerate at 106-1.

But the innings disintegrated when Samarawickrama was run out and then Gunathilaka, who hit four boundaries and a six, reverse swept legspinner Shadab Khan and was caught in the 17th over.

Substitute fielder Mohammad Nawaz then ran out dangerman Seekkuge Prasanna and also took two smart catches in the deep, including the dismissal of captain Thisara Perera (3).

Ashraf achieved a rare hat trick in the 19th over to make Sri Lanka 117-8 with Pakistan fielders holding onto sharp catches. Isuru Udana was brilliantly caught over his head by Hasan Ali at short fine leg and Mahela Udawatte was also smartly snapped close to the boundary by Babar Azam.

Ashraf completed his hat trick by having Dasun Shanaka leg before wicket as Sri Lanka could only score 18 runs in the last four overs.

On a slow wicket Pakistan batsmen also had to pace their run-chase with singles and twos as boundaries were hard to come by.

But Perera chipped in with the vital wickets of Ahmed Shehzad (27) and in-form Shoaib Malik (9) to reduce Pakistan to 55-4 by the halfway mark to its run-chase.

Perera then held onto a catch to get rid of Mohammad Hafeez and then returned to have Imad Wasim leg before wicket before captain Sarfraz Ahmed (28) was run out as Pakistan slipped to 113-7.

With 12 required off the last six deliveries Pakistan lost Ashraf off seamer Vikum Sanjaya's first ball.

Gunathilaka then couldn't hold onto a sharp chance in the deep which could have dismissed Ali but instead cost Sri Lanka three crucial runs before Shadab lofted the seamer for a straight six and then scampered for two runs to raise the victory.