Chasing 285 for victory, Sri Lanka got home with just two balls to spare to level the five-match series at 1-1 heading into game three in Sharjah on Sunday.
Mathews' 47 runs off 44 deliveries was enough to get his side over the line after Kumar Sangakkara (58) and Dinesh Chandimal (44) had laid the groundwork.
Sri Lanka's balanced batting performance proved enough for victory despite Ahmed Shehzad hitting a century as Pakistan racked up 284 for four from their 50 overs.
The 22-year-old Pakistan opener almost batted through the innings as he paced himself to three figures with eight boundaries in a 140-ball 124.
Skipper Misbah-ul-Haq finished unbeaten on 59 and along with Shahid Afridi (30 not out) took 51 from the final 29 balls.
Shehzad scored a century against South Africa in Port Elizabeth during last month's surprise series win and, after Pakistan were sent in, he moved them into a strong position.
Opening partner Sharjeel Khan lasted only until the second over before being trapped by Lasith Malinga (one for 78) before Mohammad Hafeez - a centurion in the 11-run opening win - bedded in alongside him.
They cautiously progressed the score to 84 in the 20th over when Hafeez (32) misjudged a second run and was caught well short by Dimuth Karunaratne's throw from deep mid-wicket.
More good fielding accounted for Sohaib Maqsood (18) when Chandimal ran around from long on to hold from a Seekkuge Prasanna long hop.
Misbah joined Shehzad in a 103-run stand that increased the tempo, with the opener reaching his fourth ODI century when he pulled a short ball from Malinga for a single.
Malinga was proving unusually costly and in the same over Shehzad flicked him to the ropes Misbah powerfully belted him back over the sightscreen.
Shehzad departed in the 46th over when he shuffled in front of his stumps to Nuwan Kulasekara, but that only brought Afridi to the crease.
The all-rounder added to Malinga's woes with a six that Tillakaratne Dilshan got a hand to as it flew over the rope.
Another maximum in Kulasekara's final over, which cost 15, added to the late damage as Afridi finished unbeaten on 30 from 15 balls.
Sri Lanka made a bright start to their run chase, moving to 49 without loss before they were knocked out of their stride by successive run-outs for openers Kusal Perera (16) and Dilshan (40).
Sangakkara and Chandimal steadied the ship, taking the score from 65 for two to 159 before Sangakkara was removed by Saeed Ajmal.
Chandimal followed two overs later when he was bowled by Junaid Khan, who repeated the trick to remove Thisara Perera (five) in his next spell to leave Sri Lanka wobbling on 173 for five in the 36th over.
Mathews soon restored calm to the Sri Lanka ranks as he and Kulasekara (32) took the score well beyond 200.
Prasanna (six) and Karunaratne (16no) also chipped in as Mathews steered Sri Lanka to within sight of victory before he was removed by Afridi in the final over, leaving Sachithra Senanayake (six not out) to hit the winning boundary.