Pakistan atoned for their horrorshow against India by clinching a shock 19-run victory over South Africa in a rain-affected day-night game at Edgbaston to reignite their hopes of reaching the Champions Trophy semi-finals.

Three days on from an insipid 124-run defeat against their neighbours, a rejuvenated Pakistan displayed a much-improved attitude in the field that allowed their bowlers to prosper as the Proteas were restricted to 219 for eight after opting to bat first.

David Miller’s 75 not out from 104 balls was a rare bright spot for South Africa, winners over Sri Lanka in their opener, having earlier been shackled by spin before seamer Hasan Ali impressed by taking three middle-order wickets.

Pakistan’s top-order then showed a steely resolve to guide their side to 119 for three after 27 overs, comfortably ahead of the 101 victory target required on Duckworth-Lewis before the forecast rain forced an early end to proceedings.

It is a stunning turnaround in fortunes – in a fixture that pitted the top and bottom ranked one-day sides in the competition against each other – and one that blows Group B wide open.

An unchanged South Africa had the opportunity to all but guarantee their progress to the last four with a match to spare but found the boundary rope on only 12 occasions in their 50 overs, which proved pivotal in their fourth defeat in five ODIs against Pakistan.

A win for Pakistan seemed fanciful at the start of the day but, having brought in Junaid Khan and Fakhar Zaman, they came out with plenty of purpose in bright and breezy conditions.

The introduction of spin in the ninth over on a wearing track, into its third usage after plans to play on a fresh surface were abandoned because of the recent bad weather, proved a master stroke as Imad Wasim trapped Hashim Amla lbw for 16.

Quinton de Kock then missed an attempted sweep off Mohammad Hafeez to be plumb lbw for 33 while the largely pro-Pakistan crowd were in raptures when AB de Villiers slapped his first delivery in Imad’s next over straight to point for a first golden duck in 221 ODIs.

Imad and Hafeez, despite neither offering appreciable turn, had proved difficult to get away and South Africa’s situation worsened when Hasan, like Imad, took a wicket with his second ball when Faf du Plessis chopped onto his stumps.

Pakistan were displaying a growing vigour in the field, and although Miller twice planted Hafeez into the stands at long-on he seemed to be playing a lone hand as Hasan tilted the game further in Pakistan’s favour.

Coming round the wicket, the 23-year-old removed JP Duminy, caught low at first slip, before bowling Wayne Parnell with successive deliveries to leave the top ranked ODI side reeling on 118 for six.

Miller prevented complete collapse in an unaccustomed role of anchor and, after an lbw decision against him was overturned by technology on 47, went to a becalmed fifty from 83 balls before cutting loose with a couple of lusty blows towards the end of the innings.

Fakhar, on ODI debut, gave Pakistan’s reply under lights early impetus with a quickfire 31, but the extra bounce of Morne Morkel saw the rookie meekly edge to slip before fellow opener Azhar Ali picked out third man two balls later.

Babar Azam (31no) and Hafeez calmly restored order in spite of sustained pressure from South Africa and, in particular, Morkel, who conceded only seven runs from his first five-over spell.

Morkel’s return to the attack, with light drizzle now falling, ended a 52-run stand when Hafeez pulled straight to Imran Tahir at long-leg to depart for 26.

However, the partnership had put Pakistan ahead of the D/L target and it was a position they did not relinquish before the skies opened, forcing the players off at 7.41pm – with play eventually called off two hours later.