Wonderful tries from Nehe Milner-Skudder and Ma'a Nonu had given the All Blacks a 21-3 lead early in the second half before David Pocock and Tevita Kuridrani struck back.
With 15 minutes to go there were just four points in it, but a nerveless long-distance drop-goal and penalty from Dan Carter snatched back control.
And when replacement Beauden Barrett sprinted away on to Ben Smith's clearing kick at the death history was made, with New Zealand also becoming the first three-time champions of the world.
The achievement is a fitting farewell to their phalanx of retiring greats.
Carter was outstanding under a ferocious Wallaby assault, landing 19 points from the tee, and his captain Richie McCaw was not far behind as their side was tested to the limit.
They have been the outstanding side of this generation, and once again found a way to win when the heat came on from their great trans-Tasman rivals.
The All Blacks came out at pace, McCaw smashing opposite number Michael Hooper, Wallabies' skipper Stephen Moore bloodied in the face and Carter curling over a testing penalty from out wide for 3-0 before Bernard Foley's simpler effort levelled it up.
Australia were targeting the great fly-half, Scott Sio lucky to escape a yellow card for a late hit and Sekope Kepu giving away a penalty for a high tackle that Carter popped over to retake the lead.
Matt Giteau was next to feel the intensity, clattered trying to tackle Kieran Read and unable to continue with what looked like concussion.
It was often messy and never less than flat-out, New Zealand dominating territory and possession but having to content themselves with a third Carter penalty, this time from way out right.
Then it came, a wonderful team move of magic hands and sweet timing - Conrad Smith finding space down the right, Aaron Smith popping up on his inside, McCaw taking his pass at pace and putting Milner-Skudder in at the corner.
Another perfect kick from Carter added the conversion for 16-3 at half-time and the Wallabies were sinking fast.
No team has ever scored so many in the first period of a World Cup final, and the brilliance resumed a minute into the second half.
This time it was Sonny Bill Williams, on for Conrad Smith, who sucked in three defenders before off-loading to Nonu, the wrecking-ball centre careering past the despairing Kurtley Beale and Drew Mitchell on a 40-metre run to the line.
Despite Carter's missed conversion the All Blacks appeared unstoppable, but when Ben Smith was sin-binned for tip-tackling Mitchell, Australia struck back - driving a maul off the line-out, Pocock at the back for the try, Foley curling over the conversion for 21-10.
Suddenly the men in gold sensed a chance and when Will Genia dinked a kick into the wide spaces in the right-hand corner, Ashley-Cooper was there to feed Kuridrani and send the huge centre away through Carter's tackle for another splendid score.
With Foley's conversion sailing over, 14 unanswered points had come in 11 minutes, and a thrilling contest was wide open once again.
Carter would have his revenge. From 40m out he struck the sweetest of drop-goals to extend the lead to 24-17, and then nailed a penalty from just inside the opposition half with seven minutes left.
Australia kept pressing, but when the ball was turned over in the New Zealand 22 Smith kicked clear, Barrett out-paced the despairing Pocock and the party could begin.
Man of the match - Dan Carter
After missing the 2011 World Cup final through injury, this was the perfect ending for world rugby's most perfect 10.
Carter could not dream of a better finale to his 12-year, 112-cap All Black career, and few would deny him the moment after what he has given the game down the years.
What they said
All Blacks fly-half Dan Carter: "I'm pretty grateful to be where I am considering what happened four years ago. I'm so proud of the team. To win back-to-back World Cups is a dream come true - it's a special feeling to be part of such a great team."
All Blacks captain Richie McCaw: "We said four years ago that we get on the road again with this being the end goal, try and do something no-one else has done. I'm so proud of the guys. We lost a bit of momentum in the second half but we kept our composure and came back strong."
Australia captain Stephen Moore: "It's all about New Zealand tonight - they thoroughly deserved to win. They have been the best team in the tournament and they played really well tonight.
"There are no excuses from us, I'm proud of the effort we put in and the way we fought our way back into the match. Sometimes you just come up against a better team and that was the case tonight."