Japan will face France in the semi-finals of the Olympics after overcoming Brazil 2-0 at the Millennium Stadium.
It was the Brazilians who started the better, with Cristiane coming close to opening the scoring after just two minutes.
Francielle had an effort of her own moments later, but her free kick was saved by Miho Fukumoto in an impressive opening spell.
Brazil continued to dominate as they forced a series of early corners, while Marta brought the best out of Fukumoto with 13 minutes on the clock.
Brazil's best chance fell to Renata Costa after 17 minutes, but she fired it high and wide from inside the penalty area.
The chances continued to fall for Brazil, and but for another smart save from Fukumoto, Jorge Barcellos's side would have taken the lead courtesy of Marta.
For all Brazil's pressure, the best chance of the half fell to Japan after 25 minutes, but Shinobu Ohno fired wide when Yuki Ogimi was unmarked inside the box.
Japan did eventually force the opening goal in their best spell of the match, however, when Ogimi slotted past Andreia after 27 minutes.
Brazil gained back a period of control in the final 15 minutes of the half, but they entered the break behind.
Aya Miyama had Japan's first chance of the second period, but she fired her free kick wide of the post.
It was Brazil who continued to look the most likely as the hour mark approached, and Marta whipped a free kick inches wide of the post from outside the box.
The chances continued to fall for Brazil, and Cristiane in particular, but twice she headed over from close range.
Formiga, Cristiane and Marta led Brazil's charge in the latter stages of the quarter-final, but Ohno sent Japan into the final when she found the top corner with little over 15 minutes remaining.
Both sides made changes in the final moments of the match, and Japan soaked up the threat to secure their spot in the final four.