O'Keefe produced a career-best 6-35 run figures as India lost seven wickets for 35 runs in 15.1 overs in the sensational post-lunch session and were dismissed for 105 runs to hand the visitors a crucial lead of 155 runs.
At tea on the second day of the series opener, Australia were 46 for two in their second innings.
After being shot out for a paltry total, India hit back immediately through off-spinner Ravichandran Ashwin, who dismissed openers David Warner and Shaun Marsh in quick time.
Australia skipper Steve Smith was unbeaten on 27 off 48 balls along with Peter Handscomb (8) at the final break of the day.
Also Read
Ashwin picked up two wickets for 29 in the second innings and Ravindra Jadeja went wicket-less after conceding 16 runs.
Ashwin, howeever, was let down by poor catching as Smith was dropped by Vijay at leg slip when on 27.
Earlier, resuming at the lunchtime score of 70 for three, India added 24 runs before things started happening and they lost wickets in a heap, six of them to the 32-year-old Malaysia-born O'Keefe who finished with a career-best figures that included a devastating spell of 5 for 6 in 24 balls.
O'Keefe started the collapse by dismissing well-set K L Rahul (64) in the eighth over post lunch in which he also scalped Ajinkya Rahane (13) and Wridhiman Saha to leave the hosts tottering at 95 for six.
Rahul was caught at long off while going for a extravagant shot while Rahane and Saha fell to catches off sharply turning balls from the left-arm spinner.
O'Keefe then sent home Jayant Yadav and Ravindra Jadeja in successive overs to leave India gasping at 101 for 9 and in danger of being bowled out for their lowest total by Australia at home.
(REOPENS DEL 12)
But O'Keefe could not be denied for long as he turned one across the bat of Umesh Yadav, who edged it to rival skipper Steve Smith at the slip, thus drawing curtains to India's innings in seven minutes under three hours and in 40.1 overs.
India, who polished off the last Australian wicket for the addition of just four runs in the fifth ball of the morning, were put on the ropes by left-arm fast bowler Mitchell Starc and his pace partner Josh Hazlewood.
Hazlewood, who did not use the new ball and replaced Starc in the seventh over, got the first breakthrough in his opening over by packing off Murali Vijay, who was caught behind for 10 with 26 on board.
Starc then came back for his second spell to snap up the key wickets of Cheteshwar Pujara (6) and captain Virat Kohli for a duck in just three balls to leave the hosts gasping at 44 for three.
Starc, then, stunned the hosts with a double strike in the first over of his second spell.
He first packed off another in-form Cheteshwar Pujara (6), with an unplayable snorter that the batsman gloved to Wade, while taking evasive action.
The lanky pacer then struck the biggest blow of the morning by removing Kohli, who came into the game on the back of scoring over four double centuries in four of the last five series played, for a second-ball duck.
Opener Rahul batted with composure and poise at the other end when wickets kept falling.
But all his good work went to waste after he reached his half century with a single, post lunch, and then threw away his wicket which started the dramatic collapse.
In the morning, it took Ashwin just five balls to dismiss the last Australian wicket when he induced a wild shot from Starc only to be holed out to deep mid-wicket.
With Starc's scalp, Ashwin also went past the great Kapil Dev's record most Test wickets in a home season.
Ashwin's tally of 64 wickets in 10 Test matches at home went past Kapil's earlier mark of 63 wickets in 13 Tests created way back on 1979-80 at the beginning of the great all-rounder's career.
While Ashwin ended up with three victims, Umesh Yadav was the best bowler for India with superb figures of 4 or 32, his best figures at home and second-best overall after the 5 for 93 he took against the same opponents in Perth in January 2012 on his debut.