Japan scored twice early in the second half to come from behind to defeat Spain 2-1 and advance to the round of 16 of the World Cup. Alvaro Morata scored first for Spain in the 11th minute at Khalifa International Stadium on Thursday, but Japan rallied after halftime. The Spanish striker rose highest to head a cross home, scoring his third goal in the tournament. Ritsu Doan equalised in the 48th with a left-footed shot from outside the box minutes after coming on as a substitute at halftime, and Ao Tanaka added the second one from close range a few minutes later. It took about two minutes for video review officials to confirm the ball had not gone out of bounds before the goal. Japan finished top of Group E, with Spain finishing second on goal difference – consigning Germany to elimination, despite a 4-2 win over Costa Rica on Thursday. It was a dramatic finale to the group with qualification within sight for all four teams in the final stretch of both games. In the second half, Costa Rica took the lead against Germany – a result that would have meant elimination for Spain, who were losing to Japan. But the Germans were quick to equalise and retake the lead. With the clock ticking down Japan seemed safe, until Germany made it 4-2 against Costa Rica. A late Spanish goal could have sent the Japanese from first to third place in the group. But the Samurai Blue managed to hold on and weather waves of Spanish attacks. By the end of the game, Spain had 82 percent possession, completing 1,058 passes compared to Japan’s 228. But the Japanese were simply more clinical, and Japan’s coach Hajime Moriyasu’s substitutions in the second half, including bringing on Doan, proved decisive. Japan had also shocked Germany 2-1 in its Group E opener at the same venue. Next week, Japan – who have never progressed beyond the first knockout round – will meet Croatia in the round of 16, and Spain will take on Morocco. Even before the game, it was pointed out that Spain may be better off as second in the group to avoid a potential quarter final against Brazil. The World Cup continues on Friday with the final day of the group stage to settle Groups H and G. With qualification on the line, Ghana will take on Uruguay in a highly anticipated rematch of their dramatic meeting in the 2010 World Cup quarterfinals.