Ramon Zenhaeusern of Switzerland won silver, 0.34sec behind, and Michael Matt of Austria the bronze after his compatriot Marcel Hirscher and then Henrik Kristoffersen of Norway both imploded.
Myhrer, at 35 years and 42 days, becomes the oldest man to win a slalom Olympic medal, breaking the record set by Austria's Mario Matt — Michael's brother — in 2014.
He also follows in the footsteps of Ingemar Stenmark as only the second Swede to win a men's Olympic alpine skiing gold.
“It means everything. I've been training my whole life for a moment like this,” said the unheralded Swede.
“I took a medal in Vancouver (2010), a bronze, but I've been always dreaming about the gold medal and now it's a reality and I'm totally blown away.”
Myhrer was flattered to be talked about in the same breath as Stenmark.
“He's like an institution in Sweden and one of the greatest athletes in Swedish history,” he said.
“To be named alongside him is a great honour for me. He was my idol since I was growing up, to be named alongside him is simply amazing.”
Myhrer could hardly believe his luck. He went into the second and his final run in second place behind Kristoffersen, who went fastest in the morning.
The Swede feared his chance had gone as he came to the end of his second run.
“I haven't seen the split times but that was my feeling coming into the last part and I just tried to force everything I had,” he said, after clocking a winning combined time of 1:38.99.
“Luckily it was enough to go home with the gold.”
But nerves appeared to get the better of Kristoffersen, who was going last, and his dreams of a first Olympic gold were obliterated soon after he started his second leg and he failed to finish.
Just as surprisingly, Hirscher crashed out in the first leg, ruining his hopes of a golden hat-trick in South Korea.