While India dominated the play in most parts of the three sessions, Afghanistan had their moments in the second and final session with the wickets of Dhawan (107), and the quick dismissals of Vijay (105) and Lokesh Rahul (54) off consecutive overs.
Troubled by two rain breaks during which Vijay found himself stuck in the 90s, the Tamil Nadu opener kept his composure to notch up his 12th Test hundred in the final session.
Vijay hit pacer Wafadar for a four over point to bring up his ton and together with Rahul, who by then had registered his half century, forged a valuable 112-run stand for the second wicket.
With his 12th Test ton, Vijay also became the batsman with most first innings centuries without one in the second innings.
But soon after reaching his century off 143 deliveries, Vijay found himself trapped leg before by Wafadar even as the review did not help his cause.
The visitors struck in the very next over when pacer Yamin Ahmadzai induced a faint inside edge off Rahul which uprooted his off-stump and as a result brought Pujara and Rahane together.
Rahane survived a caught behind decision early in his innings before being saved by a review but failed to make the most of the opportunity as Rashid Khan caught him plumb in front after two frustrating sessions.
Rashid could have immediately got his second Test wicket in the form of the dangerous Pujara, who on 30 was dropped at first slip by Mohammed Nabi.
But Nabi soon rectified the mistake with a superb catch at leg slip to pack back the Saurashtra batsman off the 17-year-old spinner Mujeeb.
India immediately lost another wicket when stumper Dinesh Karthik (4) departed off an unnecessary run-out with the scoreboard at 334/6.
Thereafter, Ashwin and Pandya joined forces and the duo played out the rest of the day cautiously.
Earlier, opting to bat after winning the toss, India got off to a breezy start with Dhawan smashing a quickfire century to pile up 158/0 at lunch in the lop-sided opening session.
Dhawan looked in sublime touch right from the start, punishing the pace duo of Ahmadzai and Wafadar for glorious boundaries before taking his SunRisers Hyderabad teammate Rashid to the cleaners.
Dhawan looked unstoppable and got to his seventh Test ton in a mere 87 balls even as the Afghan spin trio of Nabi, Rashid and Mujeeb seemed all at sea with this format.
For the Afghans, Ahmadzai was the pick of the bowlers with a couple of wickets while Wafadar, Rashid and Mujeeb contributed with one wicket apiece.