At lunch on the final day of the Rawalpindi Test, South Africa were clearly on top, needing just 151 runs with seven wickets in hand. The predictor on the official broadcast said South Africa had a 75% chance of winning from there. But then everything turned when the new ball was available, with Hasan Ali and Shaheen Shah Afridi ripping through South Africa as seven wickets fell for 33 runs, and Pakistan won the series 2-0. It was a "tough win" compared to the seven-wicket win in Karachi, according to captain Babar Azam, but most pleasing because "everyone played a role" and the team "finished off well".

"This is Test cricket and you can't afford to take anything easy," said Azam, who became the fifth Pakistan captain after Fazal Mahmood, Mushtaq Mohammad, Javed Miandad and Saleem Malik to start their Test captaincy stints with a series win. "At times, when they [Aiden Markram and Temba Bavuma] were having a good partnership, we didn't have negative thoughts in our minds, about losing it from there. We had a clear message and understanding that another couple of wickets and we have the game. And that is what happened when we took the new ball and our fast bowlers brought us back.

"But this was a tough win as compared to the one in Karachi, because they were settled and on the last day you never know how the pitch is going to behave. It was a slow pitch with the older ball coming soft, but then that eight-over spell with the new ball turned the game around and it was a good competitive win."

"There was no pressure as such, but whenever I feel I am stuck and need help, I reach out to Rizwan and Azhar. It's not like I just go and impose myself, but I ask around, discuss and take their counsel before making any decision"
Babar Azam

Hasan, whose last Test appearance before this series was in January 2019, returned a ten-wicket match haul. Afridi's burst with the second new ball - he picked up 4 for 51 - sparked the collapse. And before that Mohammad Rizwan, who won the Player of the Series award, scored 115* in close to five hours and put on valuable partnerships with the tail - 53 with Yasir Shah for the eighth wicket and 97 with Nauman Ali for the ninth - which proved decisive in the end.

"At times we are thinking of sticking around for 250 to 260 [as South Africa's target] but Rizwan's innings was outstanding and those partnerships from Yasir and Nauman gave us vital runs to put up a good total at the end [setting South Africa 370 to win]," Azam said. "Hasan with the ball showed some really good commitment on his comeback, so this is all teamwork, and these are very important factors. Individual performances don't really matter and you see everyone played a role and we finished off well. There were some mistakes and we are definitely going to try and improve them going forward. Wins always bring in confidence as a team, and I am looking forward to taking this form to the T20 series [of three games, with the first on February 11]."

The 2-0 series result was crucial in other ways too, with the PCB having put pressure on the team management to get its house in order. The PCB cricket committee had opted against making big changes following the disappointing tour of New Zealand, resolving instead to meet again after the home series against South Africa. The win should therefore, help, with Pakistan moving up to No. 5 in the ICC Test rankings.

"It was a much-needed win for us as a Test team," Azam acknowledged. "We were rebuilding and it takes time with new players and for me as a fresh captain. So it has been a learning phase and we tried to keep it as simple as possible. We intend to give players the required confidence and back them with their game so that they feel comfortable, and now the result is here with every player playing his role and it's good to be in the top-five teams in the world. We would like to extend our victory streak to rise higher in the ranking."

The result was the right one, but Azam's team was tested in both games. In Karachi, South Africa were 185 for 2 in the second innings before being bowled out for 245. This time, while Markram and Bavuma were there, Pakistan were in trouble.

"There was no pressure as such, but whenever I feel I am stuck and need help, I reach out to Rizwan and Azhar [Ali, the previous Test captain]," Azam said. "It's not like I just go and impose myself, but I ask around, discuss and take their counsel before making any decision. You have your plans and you go session by session and the proceedings keep on fluctuating, with the other team sometimes getting an advantage - after all, they are also competing. So it's all about patience and keeping your calm and remaining cool, no matter how tough the situation is. There is always a plan and you have to stick with it and wait for things to fall your way. This is what I am told and this is what I am trying to do as well."

Umar Farooq is ESPNcricinfo's Pakistan correspondent