Ireland's summer series in Australia will come down to a winner-takes-all finale in Sydney next week after securing a first away win in Australia in exactly 39 years.
With big hitters like Johnny Sexton and Tadhg Furlong back in the starting XV following the 18-9 first Test reversal, Joe Schmidt's Six Nations champions produced some of their best rugby of the season as they over-powered the Wallabies.
Both sides will count the cost of this bruising encounter in the coming days after a host of players were forced off injured, but they will have to do it again in seven days' time. Ireland have the wind in their sails after tries from Andrew Conway and Furlong and a 16-point haul from Sexton saw them home 26-21 in front of an attendance of nearly 30,000.
Australia started like an express train in Melbourne and were ahead inside two minutes as Bernard Foley wrong-footed Dan Leavy and sent Kurtley Beale through a big gap. The centre rounded Rob Kearney to touch down under the posts.
Foley nailed the conversion but the momentum shifted back Ireland's way when winger Marika Koroibete was sent to the sin bin for a dangerous tackle on Kearney.
Sexton put the ball in the corner for his forwards to maul and, after an initial shove, Conor Murray exploited the man advantage by floating it wide to Conway who scored in the corner.
Sexton levelled with the touchline conversion and added a penalty earned by a dominant scrum effort in front of the posts. He added another after O'Mahony forced a breakdown infringement and also punished Caleb Timu's deliberate knock-to make it 16-7.
Having promised to fix their own discipline woes after the first Test, though, Ireland conceded three penalties in quick succession to allow Australia back into it.
Furlong went off his feet at an attacking ruck, before Devin Toner played an opponent in the air to allow Foley to kick to the corner. Once there, the Wallabies turned the screw and earned a penalty try as Cian Healy was shown a yellow card for his illegal attempts at stopping the maul.
Ireland survived their 10 minutes without Healy and might have even extended their lead if Furlong had spotted Garry Ringrose on his shoulder after making an impressive break, but they had to be content with a 16-14 lead at the interval.
A physical game saw both coaches go to their replacements early but Ireland handled the disruption better and went on the attack, with Keith Earls scything through the defence from a superb Sexton pass.
Jack McGrath and Earls were denied tries by marginal decisions, but both times play came back for Irish penalties and after Sexton kicked to the corner, they finally got their reward as Furlong powered through Nick Phipps' tackle to score.
Sexton converted but Ireland were made to sweat for their win as McGrath saw yellow and Taniela Tupou forced his way over from close range.
Foley converted to make it a five-point game with less than two minutes remaining but despite finishing with a makeshift team, the visitors held on