Foss was fourth-fastest through the first time split, second-fastest 20 minutes later at the second check, and stormed home as the others struggled to claim the biggest win of his career.
The winner of the Tour de l'Avenir in 2019 – the Tour de France for under-23 riders – Foss has had a solid career as a domestique and finished ninth at the Giro d'Italia in 2021, but before today his only wins had been three Norwegian national titles – two in the time trial and one in the road race.
Foss was stunned at what he had accomplished.
"It really feels like I am in some kind of dream. I don't believe it, it's so unreal. I got the signals during the ride that my legs are really good, and I was confident my shape was good but this is more than I could ever dream for.
"I wouldn't say I'm the guy with the greatest confidence so I didn't believe until it was over, but I really felt like I got out everything I could, I gave it my best and couldn't have done anything better. This is unbelievable.
"If I was top 10 I would have been really satisfied and even top five I was hoping for, so to wear the jersey will be really special and I will try to honour it as good as I can.
"I had really good coaching and we prepared really well, it was a perfectly executed race."
In the women's race, Ellen van Dijk defended her title and claimed a third time trial gold medal.
The Dutch star maintained a perfectly paced cadence to beat Australia's Grace Brown by 12.79 seconds. Swiss rival Marlen Reusser took bronze.
"It was the perfect course for me. [But] I never thought I would win," said the 35-year-old who won her first gold in 2013. "I had no idea how I was riding. I paced my effort really well.
"It was nice to see Reusser a little bit ahead of me near the end, so I knew it wasn't a bad day for sure. But I was so surprised at the finish."
Kiwi Ella Wyllie finished 29th out of 41 riders who finished the race, 5.28 behind van Dijk.