Pecker is a key witness in the case against the former US president, who is accused of falsifying business records to cover up hush-money payment
The hosts declared their second innings on 323 for four in the final session of day four in Visakhapatnam.
South Africa were 11 for one at stumps with Aiden Markram, on three, and Theunis de Bruyn, on five, at the crease.
The visitors need another 384 runs and India nine wickets on the final day to get ahead in the three-match series.
Ravindra Jadeja struck early after trapping first-innings centurion Dean Elgar for two in the fourth over of the innings.
The left-handed Elgar, who made 160 in the first innings, was given not out by the on-field umpire only for India to get the decision overturned with a TV review.
Markram and de Bruyn then played out the remaining overs from spinners Ravichandran Ashwin and Jadeja until bad light forced the extended play - to make up for lost time due to thunderstorm on day one - to be called off.
Sharma, who made 176 in India's first innings of 502 for seven declared, is the first batsman to hit two tons in his first match as a Test opener.
He also hit 13 sixes, the most in a Test match, breaking Wasim Akram's record of 12.
Sharma put on 169 with Cheteshwar Pujara, who made 81, to frustrate South Africa after the loss of opener Mayank Agarwal for seven.
Pujara was trapped lbw by Vernon Philander after he completed his 21st Test half-century.
Sharma survived a reprieve on 50 when he was caught at the boundary off Dane Piedt. Replays indicated that fielder Senuran Muthusamy's foot had touched the rope.
He was finally stumped off Keshav Maharaj as he attempted a big hit.
Jadeja hit a 32-ball 40 before being bowled by paceman Kagiso Rabada.
Maharaj struck before lunch, grabbing the key wicket of Agarwal, who hit 215 in the first innings, but the bowlers then struggled.
Earlier, Ashwin completed a haul of seven wickets as South Africa were bowled out for 431 in the morning session.
Ashwin got overnight batsman Maharaj out for nine and then trapped Rabada, leaving the Proteas 71 runs behind.
Elgar was the hero of the South African innings with his 12th century that revived the tourists' batting after they had slipped to 63 for four.
His century partnerships with skipper Faf du Plessis, who made 55, and Quinton de Kock, who hit 111, were key to the Proteas fightback.Scoreboard
India 1st innings 502-7 dec (M. Agarwal 215, R. Sharma 176; K. Maharaj 3-189)
South Africa 1st innings (overnight 385-8)
D. Elgar c Pujara b Jadeja 160
A. Markram b Ashwin 5
T. de Bruyn c Saha b Ashwin 4
D. Piedt b Jadeja 0
T. Bavuma lbw I. Sharma 18
F. du Plessis c Pujara b Ashwin 55
Q. de Kock b Ashwin 111
S. Muthusamy not out 33
V. Philander b Ashwin 0
K. Maharaj c Agarwal b Ashwin 9
K. Rabada lbw Ashwin 15
Extras (b12, lb4, nb5) 21
Total (all out, 131.2 overs) 431
Fall of wickets: 1-14 (Markram), 2-31 (de Bruyn), 3-34 (Piedt), 4-63 (Bavuma), 5-178 (du Plessis), 6-342 (Elgar), 7-370 (de Kock), 8-376 (Philander), 9-396 (Maharaj), 10-431 (Rabada)
Bowling: I. Sharma 16-2-54-1 (nb1), Shami 18-4-47-0 (nb1), Ashwin 46.2-11-145-7, Jadeja 40-5-124-2 (nb1), Vihari 9-1-38-0 (nb2), R. Sharma 2-1-7-0
India 2nd innings
M. Agarwal c du Plessis b Maharaj 7
R. Sharma st de Kock b Maharaj 127
C. Pujara lbw Philander 81
R. Jadeja b Rabada 40
V. Kohli not out 31
A. Rahane not out 27
Extras (b8, lb2) 10
Total (4 wickets dec, 67 overs) 323
Fall of wickets: 1-21 (Agarwal), 2-190 (Pujara), 3-239 (R. Sharma), 4-286 (Jadeja)
Did not bat: G. Vihari, W. Saha, R. Ashwin, I. Sharma, M. Shami
Bowling: Philander 12-5-21-1, Maharaj 22-0-129-2, Rabada 13-3-41-1, Piedt 17-3-102-0, Muthusamy 3-0-20-0
South Africa 2nd innings (target 395)
A. Markram not out 3
D. Elgar lbw b Jadeja 2
T. de Bruyn not out 5
Extras (lb1) 1
Total (1 wicket, nine overs) 11
To bat: T Bavuma, F. du Plessis, Q. de Kock, V. Philander, S. Muthusamy, K. Maharaj, D. Piedt, K. Rabada
Fall of wicket: 1-4 (Elgar)
Bowling: Ashwin 5-2-7-0, Jadeja 4-2-3-1
Toss: India
Umpires: Chris Gaffaney (NZL), Richard Illingworth (ENG)
TV Umpire: Nigel Llong (ENG)
Match referee: Richie Richardson (WIS)
Pecker is a key witness in the case against the former US president, who is accused of falsifying business records to cover up hush-money payment
The oil and gas conglomerate and Fifa, the world governing body, sign major sponsorship agreement
Toomaj Salehi risks being hanged after the conviction on the Shariah charge of "corruption on Earth" by a Revolutionary Court
Aid groups warn any invasion would add to already-catastrophic conditions for Gaza's 2.4 million people
The American they will face Australia and Serbia on July 15 and July 17 as part of their preparation for the Paris Olympic Games
The leaders emphasise that the deal to release the hostages would bring an immediate and prolonged ceasefire in Gaza
Dubai-based Sumit Augustine has had a philosophical approach towards spending
The regional upswing also defies oil production cutbacks