Holm, the world outdoor silver medallist in Paris last year, failed twice at 2.34 but then cleared the bar with his final attempt.
With his next jump he cleared 2.36 before facing an anxious wait while he waited for his opponents to attempt the mark.
None managed and Holm was confirmed as champion. American Matt Hemmingway was second and Jaroslav Baba of the Czech Republic took the bronze.
Holm, one of the world's smallest high jumpers, raced on to the track when Baba missed with his final attempt at 2.34 and embarked on jubilant victory celebrations with the Swedish spectators massed behind the high jump stand.
He is the only Swede to win the Olympic title with former world record holder Patrik Sjoberg finishing among the minor medals in three successive Games.
Hemingway, a distant relative of the author Ernest and who took two-and-a-half years out of the sport to pursue other interests, failed three times at 2.36, as did Baba.