At the break, Agarwal was close to his third test 100 and batting on 91 runs. Rahane was unbeaten on 35 runs.
India took a 38-run lead as Bangladesh managed only 150 runs in its first innings on Thursday.
Starting from overnight 86-1, India was in some trouble early as it lost two wickets in quick succession.
After crossing 100 in the 30th over, medium pacer Abu Jayed (3-58) removed Cheteshwar Pujara (54) and star batsman Virat Kohli in the space of two overs.
Pujara started the session in a hurry as he reached 50 off 68 balls. He was then caught at wide fourth slip off Jayed in the 30th over.
The big moment came an over later as Kohli was out lbw for a two-ball duck. The umpire had first refused to give the decision but Bangladesh opted for DRS review and was successful.
Rahane then rescued the innings with Agarwal and put on 50 off 86 balls for the third wicket. In doing so, he crossed the 4000-run mark in test cricket.
Agarwal had earlier reached 50 off 98 balls, and then opened up to play a few more shots, including a six.
The duo was going well when there was another big moment pre-lunch. In the 47th over, Agarwal survived an lbw shout via DRS off Mehidy Hasan.
The off spinner was initially successful in his appeal, but on review from the batsman, the ball seemed to be floating over the stumps. The decision was reversed.
On day one, Indian pacers shared seven wickets as Bangladesh failed to take advantage of batting first.