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 yesterday.
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 had set themselves up nicely at 159-2 with Kumar Sangakkara (58) and Dinesh Chandimal (44) before Mathews came into his own.
More From This Section
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).
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.