Top seeds Fiji edged a faltering New Zealand to set up a rugby sevens semi-final against unheralded Japan in their bid for a first ever Olympic medal.
The other last-four match will see Britain, who beat Argentina 5-0 thanks to Dan Bibby's extra-time try, up against South Africa, who ran out comprehensive 22-5 winners over Australia.
In a dramatic day's rugby at the Deodoro Stadium, the Fijians, led superbly by playmaker Osea Kolinisau, held on at the death for a 12-7 victory over the Kiwis, who had scraped into the quarters by a solitary point on points difference from the United States.
"Those quarters you just want to get through them with 12 fit men, which we've done," said Fiji coach Ben Ryan.
"We've got one aim and that's to win gold medal, not silver or bronze.
"Sometimes it's dangerous to set out goals as a coach, but we're number one in the world, we're not trying to be arrogant, we're saying this is what we want."
Kolinisau rounded off a superb length-of-the-pitch move to get the scoreboard ticking for the double defending Sevens Series champions.
New Zealand responded through Gillies Kaka, who gathered his own chip to touch down for a try he also converted for a 7-5 half-time lead.
In a tactical match with both sides utilising the offload to the maximum, Jerry Tuwai shimmied his way through to restore Fiji's lead, Kolinisau converting.
But with eight seconds to go, the Fijians infringed to hand New Zealand one last improbable chance, the islanders managing to hold their nerve to advance.
Kiwi coach Gordon Tietjens, who saw code-swapping star Sonny Bill Williams ruled out with an Achilles injury in his first game, said: "It's been an up and down tournament for us in terms of consistency.
"It's obviously disappointing but it went right down to the wire. We're not looking for any excuses, Fiji deservedly beat us."
Ryan said the result was an example of how dramatic the game of sevens could be.
"As I came into this game, I saw New Zealand had one win and two defeats and us three wins," said the former England sevens player said.
"It makes no difference, if they'd had a break and scored to win at the end, no one cares about that record."
Fiji's opponents in Thursday's semi-finals, Japan, pulled off one of rugby sevens' biggest shocks when they beat New Zealand 14-12 in their opening pool match.
And they continued their fine run of form by nipping France 12-7 in their quarter thanks to a last-gasp try from livewire Teruya Goto following a first try from Lote Tuqiri that was cancelled out by Frenchman Damien Clerc.
"Honestly? I thought we'd come here, win a few games, give it a good go, I thought we'd be lucky to make the quarters let alone the semis. So I don't know what's happened here!" said Japan's outstanding New Zealand-born playmaker Lomano Lemeki.
"The way it's gone so far, I think we're still in with a big chance. We just need a few calls to come our way, maybe a few yellow cards and we could be in for a medal.
"There's no pressure on us, the pressure's on the big teams, they are the ones supposed to be winning the medals, not us."
Fiji coach Ryan also played down perceptions of added pressure on his team.
"It's not 'little old Fiji'. We're in the papers on the front and back pages every night, we're in the 6 o'clock news every night," he said.
"Everybody's a household name, the pressure's on them in our bubble in the Pacific every single day. That's not the same with any other team in this tournament... they're not getting pressure they're not used to."