New Zealand, the world No 8, looked in control when they led 2-0 with fine goals from Hugo Inglis and Shea McAleese.
However, Germany scored from two penalty corners through Moritz Furste in the second half, the second with 40 seconds left, then broke away with the clock counting down.
The cross swung in from the right and Florian Fuchs stretched forward to nudge the ball into the New Zealand net with only 1.8s remaining.
Germany advance to play world No 7 Argentina in their semifinal.
The last time New Zealand had beaten Germany was in India in 2009. They have conceded 23 goals in their last four games against them, but this time they had bags of resolve, defended resolutely but could not deny the indefatigable Germans at the death.
"It's a bitter pill it will hurt for a long time," New Zealand coach Colin Batch said.
Ryan Archibald, expected to retire after a fine career, said he was "devastated".
"Not a lot can make it feel better right now," he said.
''Germany kept pushing. We weren't quite composed enough."