Skipper Rohit Sharma, on 17, and Shubman Gill, on 18, looked positive and attacked the Australian spinners, who bowled five of the 10 overs before close of play.
The opening pair smashed four boundaries between them including a big six by Gill off senior Australia spinner Nathan Lyon.
Khawaja stood out in his marathon knock which ended on the first ball after tea when Axar Patel trapped the left-hander lbw, a decision that was denied by the on-field umpire but successfully reviewed by India.
Todd Murphy (41) and Lyon (34) kept the Indian bowlers frustrated in a 70-run stand for the ninth wicket before Ashwin broke through for his 32nd five-wicket haul in Tests.
Ashwin trapped Murphy lbw before dismissing Lyon to wrap up the innings.
In what has been a low-scoring series, giant all-rounder Green got his first international hundred with a boundary in the second session and was greeted with a hug from Khawaja.
Ashwin snared two wickets in one over after a wicketless first session for the hosts.
He broke the Khawaja-Green stand – Australia’s highest Test partnership in India since 1979 – after he got Green caught behind for 114 off a delivery sliding down the leg side.
Khawaja, who struck his first Indian Test ton on day one and 14th overall, kept up the grind to break the Australian record for longest Test innings in India.
The previous record was Graham Yallop’s 392-ball knock in Kolkata, also in 1979.
Khawaja resumed on his overnight 104 and took charge after Australia elected to bat in their bid to square the series 2-2.
The hosts need a win to clinch the four-match series and secure a berth in the World Test Championship final in June at The Oval.
Steve Smith is captaining Australia in the absence of regular Test skipper Pat Cummins.
Australia’s players wore black armbands on Friday after it was announced that Cummins’ mother had died.