Set 285 to chase, Sri Lanka needed 16 off the last two overs and four off the final, as number ten batsman Sachitra Senanayake drove Shahid Afridi for boundary to seal a tense win for his team with two balls to spare.
Skipper Angelo Mathews was named name of the match for holding his nerves till the very end scoring crucial 47 runs for his team.
The win levelled the five-match series at 1-1 after Pakistan won the first match by 11 runs in Sharjah on Wednesday.
Ahmed Shehzad smashed a career best 124 off 140 balls for his fourth one-day century as Pakistan posted a challenging 284-4 in 50 overs after being sent in to bat.
Sri Lanka needed 44 off the last six overs as Angelo Mathews (47) and Dimuth Karunaratne (16 not out) held their nerves during a match-turning 44-run stand for the eighth wicket.
Sri Lanka had set themselves up nicely at 159-2 with Kumar Sangakkara (58) and Dinesh Chandimal (44) before Mathews came into his own.
When on 29, Sangakkara completed 12,000 one-day runs in his 359th match. He is the fourth batsmen to score 12,000 or more runs in the one-day chart led by now retired Sachin Tendulkar of India (18,426 in 463 matches) followed by Australian Ricky Ponting (13,704 in 375) and Sri Lankan Sanath Jayasuriya (13,430 in 445).
Sangakkara reached his 82nd half-century off 54 balls but eight runs later played Ajmal onto his stumps. In all he hit four boundaries and a six off 67 balls.
Sri Lanka were off to a swift 48-run start by Tillakaratne Dilshan (40) and Kusal Perera (16) before both fell run out to leave Sri Lanka 65-2.
With the ball hard to grip for the spinners as dew fell, Sangakkara and Chandimal added 94 for the third wicket.
Nuwan Kulasekara chipped in with a 33-ball 32 with two sixes and three fours to up the scoring in the final overs.
Mathews praised his team’s effort and fightback.
“It was a complete team effort,” said Mathews. “Pakistan were cruising along and were due for another big score but we kept them to 284 and then held our nerves for this win.”
Pakistan captain Misbah-ul Haq said: “We gave away many runs in the final overs and we need to improve our death bowling if we want to win the series.”
Earlier, Shehzad steadied Pakistan’s innings during a 76-run second wicket stand with Mohammad Hafeez (32).
Shehzad also added another 105 runs for the fourth wicket with skipper Misbah-ul-Haq (59 not out).
Shehzad took a single off Malinga to reach his hundred, which came off 121 balls with the help of six boundaries. But he was finally trapped leg-before by Kulasekara in the 46th over.
Shehzad’s previous best in a one-day was 115 against New Zealand at Hamilton in 2011. Misbah kept the charge going alongside Shahid Afridi (30 not out in 15 balls) as Pakistan scored 92 in the last 10 overs.
Misbah hit two fours and a six in his 34th one-day half-century while Afridi hit two sixes and a boundary.
The Sri Lankan bowlers, who conceded 322 in the first game in Sharjah, kept a tight line and length but were hurt because of injuries to skipper Mathews and Thisara Perera who couldn’t complete their overs.
The remaining matches will be played in Sharjah (Sunday) and Abu Dhabi (Wednesday and Friday).