Four-time champions Germany sensationally crashed out of the World Cup despite a 4-2 victory over Costa Rica in their last Group E match on Thursday, tumbling out at the first hurdle for the second consecutive time.
Japan topped Group E with six points following their 2-1 win over the Spaniards and will face Croatia in the last 16 while Spain will take on Morocco. Costa Rica finished last on three points.
Fellow substitute Niclas Fuellkrug added a fourth in stoppage time but even that was not enough to prolong their World Cup stay.
"We wanted to score three or four goals in the first half but then we made mistakes. If we had converted those chances, 16 of them.