With favourites Germany and the United States - who had won six of the last eight titles between them - already eliminated, Japan made the most of their unexpected opportunity.
Hinata Miyazawa gave them a 38th-minute lead before Saori Takarada (57) and Fuka Nagano (65) put the game beyond the reach of Spain who grabbed a late consolation through Candela Andujar.
England defeated France 4-2 on a penalty shoot-out to finish third after their play-off had ended 1-1.