The Norwegian attacked Fabian Greiller (TotalEnergies) and Alessandro Verre (Arkéa-Samsic) 30 kilometres from the finish and held off all attempts to reel him in, lapping up the support from fans in Trondheim as he soloed to the line.
The 23-year-old's effort was enough to overhaul Victor Lefay's (Cofidis) lead in the general classification to become the first Norwegian to triumph at the race since 2013.
"I felt quite bad yesterday, so today we just agreed to see how the legs would react," Leknessund said after the stage.
"But the attacks kept going and we agreed the whole team had to participate.
"After a while the legs felt better and I went away with three guys, I was just thinking this is a normal breakaway for the TV, I didn't think it would go all the way to the line.
"My goal was to just get one lap on my own to enjoy the crowds, it's in Norway and I know so many people around here but when I was there I just went full gas.
It's really nice. It's my home race, this is a race I watched since I was a small kid and one of the reasons I started cycling, so it's unbelievable actually. I'm quite emotional to be honest."
The attacks began right from the start of the 159 kilometre stage with riders trying to get away everywhere until the trio of Leknessund, Greiller and Verre made the decisive move with 65 kilometres to go.
The group carved out a lead of over two minutes on the trailing peloton with Cofidis on the front, before Leknessund jumped away as the finishing circuit in Trondheim began in the last 30 kilometres.
Nicola Conci (Alpecin-Deceuninck) then launched a big acceleration in pursuit of Leknessund, passing Tylhot Tower with a 45 second deficit to the Norwegian.
On the final lap of the circuit, Conci was still chasing with Lafay, Quinten Hermans (Intermarché-Wanty Gobert) and Kévin Vauquelin (Arkéa-Samsic) accelerating behind.
But it was all in vain as Leknessund was too strong for them all, crossing the line with his arms raised 16 seconds ahead of Conci.
The Norwegian's dominant performance vaulted him into the Midnight Sun jersey with Hugo Houle (Israel Premier-Tech) finishing second 8 seconds back, Conci rewarded with third overall for his efforts on the day just 9 seconds from first.