Scotland failed to end a 117-year wait for a first ever win against New Zealand as the beleaguered All Blacks fought back to win a thriller at Murrayfield.
The tourists raced into a 14-0 lead after just seven minutes thanks to tries from Samisoni Taukei'aho and debutant Mark Telea.
But Scotland were level a mere seven minutes later when Stuart Hogg was taken out for a penalty try and Darcy Graham intercepted and raced in at the corner.
The returning Finn Russell added three penalties as Scotland made it 23 unanswered points, but they were made to rue some missed opportunities, and Jack Dempsey's sin-binning in the final quarter.
The All Blacks - who had been on the back foot for so much of the game - took full advantage as Scott Barrett crashed over and brother Jordie converted to give them the lead again, before Telea added his second to seal victory with five minutes left.
The last time the All Blacks were in Edinburgh in 2017, only a Beauden Barrett try-saver on Hogg stopped a potentially historic victory, as the tourists held on for a five-point win.
Then, as now, the Scotland players and fans were inspired by the presence of Doddie Weir. The legendary lock presented the match ball five years after launching his foundation, which has raised millions for motor neurone disease research.
But even with that powerful emotional lever to reach for, few had any hope of a repeat of 2017's close game, never mind a first ever win over New Zealand. Even this imperfect version of them.
And any at Murrayfield who did have hope might have thought of heading for the pub when Taukei'aho crashed over with the visitors' first attack and Telea pounced on a cross-field kick for a debut score to make it 14-0 after seven minutes.
But Scotland found whatever it is they misplaced at the end of 2021. Townsend's team re-discovered some intensity, accuracy, and inspiration.
Hogg, back to his best, broke the line and kicked through, forcing Anton Lienert-Brown to take him out to prevent a try. Off the centre went to the bin, and Scotland had seven points.
It was soon 14 when Graham picked off David Havili's slack pass and sensationally scooted past two black shirts.
Russell, the main protagonist having been parachuted straight in at fly-half after not being picked for the original squad, added a penalty to his conversion to give the Scots a 17-14 lead at the break.
It could have been more, too. Graham flew in at the corner but had a foot in touch, Jamie Ritchie was done for a double movement over the line, and Duhan van der Merwe was stopped just short.
When play resumed, the ordinary looking All Blacks strayed offside and the nerveless Russell made the lead six. Was the unthinkable unfolding?
Hogg went inches away from a try, and then a scrum penalty allowed Russell to extend the gap to nine points, and Scotland's 23rd without reply.
Murrayfield swelled with belief. By this stage New Zealand were in double figures for penalties conceded, their aura fading fast.
Jordie Barrett's penalty made it a six-point game again as the tourists stopped the flow of Scottish points with 18 minutes left.
Then came the turning point. Dempsey was sin-binned for a deliberate knock-on as he raced off the line to thwart an All Blacks surge, and from the resulting scrum the visitors pounced.
Scott Barrett burrowed over from close range, and brother Jordie converted to put New Zealand back in front by a single point.
At that stage, there was an inevitability about the outcome. And sure enough, the All Blacks made the victory safe.
Relentless pressure released Telea out wide to thud over the whitewash in the corner and just about ground the ball, and Barrett nailed the touchline conversion to rub salt into Scotland's wounds.
That's win number 30 against the Scots for New Zealand without defeat in 32, but boy they were given a scare.
Line-ups
Scotland: Hogg; Graham, Harris, Tuipulotu, Van der Merwe; Russell, Price; Schoeman, Brown, Z Fagerson, R Gray, Gilchrist, Ritchie (capt), Watson, M Fagerson
Replacements: Ashman, Sutherland, Nel, J Gray, Dempsey, White, Kinghorn, Bennett.
New Zealand: J Barrett; Telea, Lienert-Brown, Havili, Clarke; B Barrett, Christie; De Groot, Taukei'aho, Laulala, Whitelock (capt), S Barrett, A Ioane, Papali'i, Savea
Replacements: Taylor, Bower, Newell, Vaa'i, Frizell, Perenara, Perofeta, R Ioane.