The Pakistani team Halts South Africa's 10-match Unbeaten Run.
The left-arm pacer claimed four wickets in the second innings after going wicketless in the first session.
First Test, the Gaddafi Stadium (day four)
The home side 378 (Imam-ul-Haq 93, Agha 93; Senuran Muthusamy 6-117) & 167 (Babar Azam 42; the spinner 5-57)
South Africa 269 (De Zorzi 104; Noman 6-112) & 183 (Dewald Brevis 54; Shaheen Afridi 4-33, Noman Ali 4-79)
The hosts secured a 93-run victory
The national team brought an end to world champions South Africa's winning streak by achieving a 93-run margin win in an exciting and hard-fought opening Test in Lahore.
The Proteas, whose 10-Test winning streak in the longest format culminated in victory over Australia in the WTC final in the month of June, were bowled out for 183 chasing 277.
Starting the day on 51 for two, they lost first-innings centurion Tony de Zorzi lbw to left-arm quick Afridi to the third delivery of the day to shift the finely-poised chase in Pakistan's favour.
Left-arm spinner Noman Ali, who claimed 10-191 in the match, dismissed Stubbs for 2 and clean bowled Dewald Brevis, who offered some resistance with a rapid 54.
Right-arm spinner Sajid Khan also took advantage of sharp turn to end opening batsman Ryan Rickelton's innings - he faced 145 balls for 45 runs - and Afridi returned in the afternoon session to knock over the lower order with a fine display of reverse swing.
He had Kyle Verreynne leg before for nineteen and bowled Prenelan Subrayen and Rabada to seal the win.
It was each team's opening game of the 2025-27 Test championship cycle and propels Pakistan straight into the number two spot after table-toppers the Australian team.
The win was built around key performances of ninety-three by opening batsman Imam and, crucially, number seven Agha which boosted them to 378.
After that slow bowlers Noman Ali and Sajid utilized favourable home conditions, as they had in their series victory over England the previous year, to sustain their lead.
The second and final Test starts on October 20.