The Slovenian, who lost ground to Vingegaard in Wednesday's first mountain stage, resisted his rival's attack in the Col du Tourmalet before going solo on the final climb to Cauterets-Cambasque and beating the Jumbo Visma rider by 24 seconds.
After Australian Jai Hindley, who claimed the yellow jersey on Wednesday, was dropped before the top of the Tourmalet, Vingegaard and Pogacar were set to fight for the stage win on the last ascent, a 16-km effort at 5.4%.
Pogacar attacked with 2.7km left, taking Vingegaard by surprise after the Dane's team had done everything to set him up for the win all day.
Overall, Vingegaard leads Pogacar by 25 seconds and third-placed Hindley by one minute and 34 seconds.