Faith was all the explanation Angelo Mathews could give for a day in which the weather itself colluded with the hosts, who sped to a thrilling seven-wicket victory, to take the series lead in Galle.

Mathews was at the crease as a dark cloud moved above the stadium, threatening to halt Sri Lanka's chase either by unleashing rain, or by blocking the last rays of sunlight.

But as the cloud loomed closer, Mathews and Kithuruwan Vithanage lashed out to hit 17 runs off a Junaid Khan over, then seven off the first two balls of the following over to hit their target moments before rain came down in a torrent. Had they waited a few balls more to launch, the match would almost certainly have ended in a draw.

Five of Sri Lanka's last six Tests have gone down to the final minutes, and Mathews was visibly elated when he struck the winning run at Galle.

"With five overs left the umpires told us that this could be the final over because of bad light," Mathews said. "So I was praying that we would be able get the required runs and get across the line. We were determined to score the runs before the umpires called off play. Luck was with us, because soon after I scored the winning the runs, the rains came down. Everything went really well so we need to thank God for that.

"We had faith in ourselves. We kept fighting till the last ball was bowled. In those five Test matches it has gone down to the wire every single time, and we kept fighting and we kept believing in ourselves."

Mathew's said the victory had been of suitable excitement for Mahela Jayawardene's final Test in Galle, which has been among the two venues where Jayawardene has been particularly prolific. Jayawardene hit 2382 runs at an average of 70.05 on what has consistently been a result-pitch.

"The win is a tribute to Mahela. What a great player he is. The way Kumar Sangakkara and Mahela were sent off in the World T20 was amazing. Great players deserve to be sent off like that. Mahela has contributed so much to Sri Lankan cricket. We just want to thank him for all his support on behalf of the team. Hopefully we can do that in the next game, and also in the next few months, in the ODIs."

The match seemed headed for a draw, when Sri Lanka were still batting in the first innings late on day four. The hosts declared 82 runs ahead mostly in hope, but Rangana Herath had an outstanding final day, taking 6 for 48 to run through Pakistan.

"The match was going nowhere, to be honest. Yesterday when we reached their target and got a lead of 60-70, we just wanted to try bowling against the Pakistanis and to try and make a game out of it. Rangana is the main bowler in our line-up. In the last three tests he has bowled about 250 overs for us, so we are grateful to him for his commitment to the team."

Andrew Fidel Fernando is ESPNcricinfo's Sri Lanka correspondent. @andrewffernando