Sri Lanka's late order batsmen held their nerve to beat Pakistan by two wickets and level the series in a match in which fortunes swung from one side to another in Dubai.
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 on Friday.
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.
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.
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 (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.
Image: Dimuth Karunaratne and Sachithra Senanayaka
Photograph: Francois Nel/Getty Images
Hafeez ton guides Pakistan to 11-run win over SL
Sri Lanka beat Pakistan, preserve No 1 ranking
Kohli, de Villiers in tussle for No 1 ODI batting ranking
Sri Lanka Cricket name Englishman Farbrace as coach
Afridi steers Pakistan to T20 win over Sri Lanka