Media playback is not supported on this device
Argentina missed what would have been a match-winning penalty in stoppage time, sending the game into sudden death.
Tom Mitchell could then have won it for Britain, only for his penalty to rebound off the post, but Dan Bibby's try soon after secured victory.
They will face South Africa in the last four on Thursday.
"I thought that our Olympic dream was over, but luck was on our side," Bibby said.
"We have only been together for 10 weeks, and to fight out there on the field, no matter what nation you are from - England, Scotland or Wales - is what a true team is about."
Argentina came second in their pool during the group stages and many of their players were left in tears after the defeat.
Media playback is not supported on this device
Fiji advanced to the semi-finals with a 12-7 victory over New Zealand, as they continued their search for a first ever Olympic medal.
It was New Zealand's second loss of the day after Great Britain defeated them 21-19 in the final group match.
Fiji will face surprise package Japan in the last four after their 12-7 win over France, while South Africa secured an emphatic 22-5 victory over Australia.
England's 2003 World Cup-winning coach Sir Clive Woodward
"The drama was amazing. I thought the Great Britain team handled the pressure really well. They really kept their nerve. The scenes at the end were just fantastic and this game will go down in the history of rugby sevens. It was that good."
England international James Haskell: "Yes the boys!!!! @TeamGB 7's pulling it out the bag. Dan Bibby take a bow. Unreal try-saving turnover from Davies in the first half."
Harlequins and England full-back Mike Brown: "What a game!! Well done @TeamGB brilliant #Rugby7s #Olympics"
Welsh rugby union referee Nigel Owens: "Never get excited over a game of rugby unless Wales or Pontyberem are playing lol. But was hiding behind the sofa for that one. Well done GB."
Great Britain's men advanced to the Olympic rugby sevens semi-finals after a dramatic 5-0 victory over Argentina in extra time.