Germany crashed out of the World Cup at the group stage for the second time in succession despite a 4-2 win against Costa Rica on Thursday.
But the Germans were eliminated from Group E due to goal difference as Japan followed up their defeat of Germany with another shock result by beating Spain 2-1.
Keysher Fuller, Costa Rica's goal-scoring hero in a 1-0 win against Japan, forced Manuel Neuer into a fingertip save after some half-hearted defending from Raum and Antonio Ruediger.
Just seven minutes into the second half, word crept around the Al Bayt Stadium that Japan had scored two quick goals to take the lead against Spain, a result which would force Germany out of the tournament.
Flick continued to chase the game, making more changes but it was Costa Rica who scored next when Juan Pablo Vargas tapped a free kick past Neuer to put his side past Spain and into the Round of 16.