Teuns reeled in numerous late attacks, launching his own bid for victory with 200 metres to go up the steep ramp into the finish at Szczyrk.
The Belgian and his teammate Rohan Dennis were in a select group of around 20 riders who pursued young Ausssie climber Jack Haig (Orica-Scott) after his frisky attack with 11 kilometres to go.
On the final descent into the finale, Haig's compatriot Dennis worked hard on the front to reduce the gap to just five seconds, the catch ultimately made just one kilometre from the line.
Teuns' win comes on the back of some hot form at the Tour of Wallonie in mid-July where he won the overall classification. But it is Teuns' first UCI WorldTour stage win.
"It's just amazing," the 25-year-old said. "There isn't much more I can say. It's a great feeling and an incredible moment for me."
"This type of stage is where my strengths lie and I had the whole team behind me and supporting me. They did a great job all day and brought me into the position I needed to be in for the final."
In a 161 kilometre stage tipped for the climbers, Sagan came around several riders in the closing metres, out gunning team mate Rafal Majka to second place and reclaimed the race lead.
"That was a tough one," Sagan said. "I managed to stay in a good position in the first four climbs and I gave my all in the steep and hard final climb. Thanks to the squad and Rafał for their excellent work today – it feels good to be back in yellow.
"As I said yesterday, my form is very good, but the race is long and we will take it day by day."
Sagan leads Teuns by just six seconds, with teammate Majka in third position at 12 seconds.
"There are still a lot of strong riders up there but I am now in the position to do a good GC," Teuns said.
"So I need to try everything to do my best and to give my best for the team. We will see how far I can go."
Earlier, the peloton happily allowed seven riders to detach and form a three minute and 30 second advantage after 60 kilometres raced. The leaders lost a minute on the second turn around the town circuit which included two categorised climbs, and were ultimately caught in the final 30 kilometres as the pace increased and numerous attacks came the bunch.
Unfortunately it wasn't all roses for BMC with Ben Hermans abandoning the race after a heavy fall. He is OK but an update from the team will be provided soon.