Agarwal, who made a double century in India's opening win, completed another hundred with a boundary off Vernon Philander in Pune.
He took the lead role despite being hit on the helmet from a bouncer by debutant paceman Anrich Nortje. He went on to hit Nortje for three glorious off drives in one over before lunch.
But the in-form batsman became Kagiso Rabada's third victim of the day after edging the ball to skipper Faf du Plessis at first slip. He made 108.
The hosts were 198 for three in 61 overs with skipper Virat Kohli on eight, joined by vice-captain Ajinkya Rahane in the final session.
Agarwal put on 138 runs for the second wicket with Cheteshwar Pujara, who made 58, to steady the innings after the fall of Rohit Sharma early in the day.
Rabada claimed opener Sharma, who edged the ball into the gloves of wicketkeeper Quinton de Kock for 14 in the 10th over.
He had Pujara caught by du Plessis just before tea. Pujara, who was dropped by Temba Bavuma before he scored, hit a six and nine fours.
Victory for India in the series will see them beat the record of 10 straight home series wins they share with Australia.