It was Roglič who led the way with a final surge that saw the rest of the elite climbers dropped in the final 500 metres as he put down the power on an uphill pinch. Alejandro Valverde (Movistar) was the first to follow the move, but dropped off the pace, forcing Pogačar to come around to stay in contact.
The Tour de France champion then timed his own attack perfectly so that he pushed in front just over the crest of the hill, with just the downhill run to the line to come as he coasted over for the win.
“In the morning we had gone by car to see the finish and the team manager Matxin had explained the route to me well, so I was aware of the toughness of the climb and I knew that it would be crucial to be in first position on the final crest to launch well into the final meters downhill towards the finish," said Pogačar.
"This success makes me very happy because, after racing here in the Basque Country two years ago, I have always had the ambition to come back and do well. It is a very beautiful race and the enthusiasm of the fans is really amazing.
With the stage win, Pogačar moved up into second overall and narrowed his disadvantage to just 20 seconds to Roglič, who has held the race lead since his opening day time trial victory.
"There are still three days of racing, all quite hard," said Pogačar. "I’m pretty optimistic because the condition is good and the team is racing very well together.”
Alejandro Valverde (Movistar) won the sprint for third place, five seconds further back, with Adam Yates (Ineos Grenadiers) and Mikel Landa (Bahrain Victorious) completing the top five at the same time deficit.
The early break of the day was always going to find the going tough, with the final climb likely to be the scene for fireworks among the top contenders for the stage and overall victory.
Mikkel Honoré (Deceuninck-QuickStep), Theo Delacroix (Interlarché-Wanty Gobert), Larry Warbasse (AG2R Citroën), Oier Lazkano (Caja Rural-Seguros RGA), Daniel Navarro (Burgos-BH), Gotzon Martin (Euskaltel-Euskadi), and Felix Gall (Team DSM) were the brave ones to try their luck and they managed to extend their advantage to six minutes at the 100-kilometres to go mark.
Lazkano went solo from just over 50 kilometres to go as the gap was being brought down rapidly from behind, but he was caught by the peloton on the penultimate climb of the stage, the Malkuartu.
At the bottom of the descent, a strong group of four moved off the front of the main bunch, with Magnus Cort and Sergio Higuita (both EF-Nippo), Aurelien Paret-Peintre (AG2R Citroën) and Richard Carapaz (Ineos Grenadiers) all making the move to try and steal a march on the peloton.
Woods and Wilco Kelderman (Bora-Hansgrohe) both went down on a corner, out of contention for the finish with the Dutchman coming off worse and failing to finish the race.
The escaped quartet reached the final climb with a narrow advantage, Carapaz dropped his former companions as he tackled the brutal 20 per cent slopes that formed the hardest sections of the climb.
Pogačar and Roglič made their move at the 2.1-kilometre mark, sweeping past Carapaz in seeming slow motion as they tackled the difficult gradients. The race leader sat on his big rival's wheel and after a while an elite chasing group of Adam Yates (INEOS Grenadiers), Mikel Landa (Bahrain-Victorious) and Mauri Vansevenant (Deceuninck-QuickStep) managed to bring the pair back.
Pogačar attacked again at 1.5 kilometres to go, Roglič was again the only one that could follow, this time on more shallow inclines. After another hard chase, David Gaudu (Groupama-FDJ) came across the gap with Yates, Landa and Valverde making it six riders at the front of the race.
Following a Gaudu surge, Roglič launched his final attack at 500 metres to go, powering away from the rest and just Pogačar able to follow. The pair had finally forged the race-winning margin, but in the end, it was Pogačar's superior knowledge of the finish that netted him the win as Roglič acknowledged afterwards.
If I had known the climb beforehand, I would have done it differently," said Roglič. "It was very technical, a super-hard climb, then a little less steep at the top and up and down after that. Tadej was better than me in the final."
The highest-placed Australian finisher was Ben O'Connor (AG2R-Citroen) in 23rd, just over a minute behind the race winner.