Japan secured their maiden World Cup quarter-final with a 28-21 victory against Scotland to thrill a joyous home crowd in Yokohama.