After a ferocious sprint finish in a packed Hyde Park, both Spirig and Lisa Norden of Sweden were given the same time of one hour 59 minutes 48 seconds.
The judges examined the photographic evidence and said Spirig's winning margin was less than 15 centimetres.
Two seconds back, Erin Densham of Australia won the bronze medal, having been in contention for gold until the final 200 metres of an enthralling duel.
"I had a feeling but I wasn't really sure," the 30-year-old Spirig said when asked if she knew she had won the gold medal. "I really needed an official to tell me. It took a few minutes and those minutes were really hard."
Fourth was Sarah Groff of the United States, in two hours dead, while British world champion Helen Jenkins was fifth, 19 seconds further back.
Race officials later issued a photograph showing the slender margin of victory, which appeared to show Norden's head crossing the finish first.
"The athlete whose torso crosses the line first is declared the winner," the ITU said in a statement.
"If the timing is so close the two athletes cannot be split, two cameras placed on the finishing line are used.
"Even though the two athletes recorded the same time as they crossed the finish line, the finish-line cameras showed Spirig's torso crossed the line first and so she was declared the winner.
"This has never before happened at an Olympic triathlon."
The swimming, cycling and running course took in some of the British capital's most famous landmarks, including Buckingham Palace.
It began with a 1.5-km swim in the Serpentine lake in Hyde Park on a day cold enough, with a water temperature of less than 20 degrees Celsius, to allow the women to wear wetsuits.
The wetsuits assisted the weaker swimmers and led to almost half the field of 56 starters, including the pre-race favourites, forming a lead group on the 43-km cycle phase.
Britain's Helen Jenkins finished fifth after being run out of contention in the final kilometre.
Lucy Hall, who finished 33rd, led out the swim and organised the pace in the bike to give Jenkins the best chance of a medal, while Vicky Holland finished 26th despite a crash.
Jenkins, who was the first British woman to win the ITU World Championship Series title, was disappointed but admitted she had nothing left to give on the day.
“I did give it everything. I just couldn’t hang in there in the last lap of the run,” said the double world champion.
“This has been the hardest ten weeks of my career. I had an injury – it’s been really hard to actually get to the start line and I’m actually amazed I was in contention for that long.
“I haven’t been able to get all of my running in and I gave it everything. The crowd helped so much, I want to thank everyone out there shouting and I gave it everything. I’m sorry it wasn’t a medal.
“I really tried and I’m so grateful to the team. Unfortunately Vicky (Holland) crashed and Lucy kept the pace on in the bike and made sure we didn’t get caught by everyone behind.
“I think the British triathlon team have been amazing – we did everything right for this one I just haven’t been able to get all the training in for this race. Everything else was right just my run legs weren’t.
“When I get tired my head just drops and my legs were just going. Congratulations to the top three girls, they really fought for that well deserved winners.
“Just after San Diego I had a problem with my knee since then it’s been a battle to get here and it hasn’t really gone away I’ve just been training through a lot of pain for ten weeks.
“We’ve had a lot of tears a lot of emotion going on but I’ve had a great team around me and we were confident that from my form in San Diego that I would still be close to it but unfortunately I just wasn’t one hundred percent there on the run.
“The good thing about triathlon is there are three sports so I could just really focus on my swim and bike and get that ready and just didn’t have quite enough today. If the race had been a few months ago I would have been alright.”
Hall, who was the youngest member of the team at just 20, admitted she had regrets about her role as domestique in the team.
“I probably should in hindsight looked back a bit more,” she said. “I knew we were spread out and everything. I kind of assumed that Helen and Vic were there, so on my part I’m sorry.”
Holland was involved in a crash with Australia’s Emma Moffatt and the 26-year-old admitted that the incident cost the chance to really influence the race.
“I was first lap round Buckingham Palace and the white lines were still a little bit wet from the rain this morning,” she said.
“I saw her (Moffatt) go down maybe a few metres in front of me and I was taking a wide line round her and I got taken out from behind.
“I would love to see the footage I think that maybe someone who also got caught in the crash tapped my back wheel.
“I got up pretty quick but couldn’t get back to the pack from there on in it was a case of not trying to hunt down these girls because they were some of the fast runners.
“So it was just a case of cruising round at the back and waiting for the run and I actually ran quicker than I thought I would.”