CENTURION, South Africa (AP) — India was left on Tuesday with a tough target of 287 to win the second test against South Africa and level the series between the top two teams in the world.

South Africa was 258 all out in its second innings in the afternoon on Day 4, with captain Faf du Plessis finally falling for 48 off 141 balls.

Du Plessis reverted to an attritional approach after seeing his team lose three quick wickets in the morning session. He featured in a partnership of 46 with Vernon Philander that edged South Africa toward a match-winning position, although the result was by no means certain.

No team has scored more than 251 in the fourth innings of a test at Centurion, meaning an India victory would be the highest ever chase at the ground. But this pitch isn't a typically bowler-friendly strip and India captain Virat Kohli made 153 in the first innings.

Top-ranked India desperately needs the win to level the three-match series.

Seamers Mohammed Shami took 4-49 and Jasprit Bumrah 3-70 for India, preventing South Africa from running away with the game in the second innings. Spinner Ravichandran Ashwin ended South Africa's innings when No. 11 Lungi Ngidi was caught on the long-on boundary, Ashwin's only wicket.

Du Plessis was the second last man out, dismissed by a one-handed catch by Bumrah off his own bowling and shortly after he had dropped a similar chance from du Plessis.

Du Plessis hit just four fours in his innings as South Africa crawled through the afternoon session. Philander was equally unadventurous in his 26 from 85 balls before he was out. He fell trying to play a rare attacking shot, caught off a mistimed pull off Ishant Sharma, who took both South African wickets in the middle session. Two overs after Philander went, Keshav Maharaj was out for 6.

Before lunch, Shami took three quick wickets to move India back into contention in a test it must win to have a chance at a first ever series victory in South Africa. Top-ranked India trails No. 2 South Africa 1-0 in the three-game contest.

Shami dismissed AB de Villiers to break his 141-run partnership with Dean Elgar, then removed Elgar and Quinton de Kock in quick succession to leave South Africa on 173-5, a lead of just 201.

India collected those three wickets in the space of six overs and for just 19 runs as South Africa's solid start to the fourth day was suddenly halted.

De Villiers (80) and Elgar (61) took South Africa from 90-2 overnight to 144 before de Villiers edged behind to wicketkeeper Parthik Patel. Elgar was caught at backward square leg, with KL Rahul holding onto the catch after a juggle. Two overs after that, de Kock was caught behind for 12.

Du Plessis and Philander shut the door, though, working their way through 156 deliveries — 26 overs — for their 46-run partnership.