Hinata Miyazawa scored twice as former champions Japan put on a counter-attacking clinic to beat Spain 4-0 and lock up top spot in Group C at the Women's World Cup.
Japan, winners of the 2011 World Cup and runners-up in 2015, will remain in the New Zealand capital to play Norway in the last 16 on Saturday, while Spain will move north to Auckland to face Switzerland earlier on the same day.
Both teams had already qualified for the knockout stage after convincing wins in their first two group matches and Japan coach Futoshi Ikeda made five changes to his side for the clash at Wellington Regional Stadium.
Spain took the initiative from the start and Japan's opener in the 12th minute was very much against the run of play.
Jun Endo on the left wing curled a pass behind the Spanish defence and Miyazawa raced in to coolly slide it into the net with her left foot.
It was Miyazawa's third goal of the tournament and the first Spain had conceded in their three games in New Zealand.
Spain continued to dominate possession and territory but the Nadeshiko hit them on the break again in the 29th minute and Ueki, released by Miyazawa, fired a shot at goal that took a deflection off Irene Paredes and ballooned over Misa Rodriguez.
Ueki returned the favour for the third goal in the 40th minute with a through ball that Miyazawa reached on the edge of the box and hammered past Rodriguez with her right foot.
Spain came out in the second half with more purpose but for all their possession and more than 900 passes, they were unable to seriously trouble a Japan defence that has yet to concede a goal at the tournament.
Meanwhile, debutants Zambia claimed their first victory at the Women's World Cup with a 3-1 win over Costa Rica at Waikato Stadium, although both teams were already out of contention for the knockout stage.
Zambia, whose first two games ended in 5-0 hammerings, finished third in Group C, as Costa Rica finished bottom and did not pick up a point in their three matches.
Defender Lushomo Mweemba scored the fastest goal of the tournament so far, with a spectacular volleyed effort at two minutes and 11 seconds, and captain Barbra Banda doubled the lead from the penalty spot just after the half-hour mark.
Zambia were awarded the spot kick after Banda went to ground inside the six yard box and the forward stepped up to calmly slot the ball into the bottom left corner, scoring the 1,000th goal in Women's World Cup history.
Playing at their second World Cup, Costa Rica were still searching for their first win in the competition and cut the deficit early in the second half, when Melissa Herrera bundled the ball home after goalkeeper Catherine Musonda was unable to clear it.
Costa Rica appealed for a penalty when midfielder Priscila Chinchilla collided with Musonda in the box, but were denied after a lengthy VAR check when replays showed forward Sheika Scott was offside in the build-up.
Herrera had the ball in the net again with around 20 minutes remaining but was ruled offside and Valeria Del Campo fired wide before, against the run of play, Zambia's Racheal Kundananji scored from Banda's cross in stoppage time to seal a historic win.
Reuters