Majka was the best climber on the 17th stage, a brutal 124.5km trek from St Gaudens and featuring four tough ascents, and extended his lead over Nibali and Spain's Joaquim Rodriguez in the mountain classification. The win was his second stage victory after he prevailed on the 14th stage in the Alps, and a third in four stages for Tinkoff-Saxo after their leader Alberto Contador crashed out.
"I'm so happy because my team worked so hard for that result," said Majka, who has 149 points in the mountain classification. Nibali has 118 and Rodriguez 112, with 80 points still up for grabs.
The Italian Giovanni Visconti was second, with Nibali taking third place to extend his overall race lead to over five minutes. "It was a nervous stage; I'm relieved," said a calm Nibali.
France's Jean-Christophe Peraud was fourth as he gained more than 50 seconds on his compatriot Thibaut Pinot, who struggled in the final climb. "In the third week, it's difficult every day but I'm happy I can hold [on to] Nibali's wheel," said the 37-year-old Peraud.
Nibali leads Spain's Alejandro Valverde by 5 minutes 26 seconds, with Pinot in third place overall, six minutes off the pace. Peraud, who is expected to fare better in Saturday's time trial, is fourth, eight seconds behind Pinot.
A group of 22 riders, featuring Rodriguez, Majka, Luxemburg's Fraenk Schleck and the Dutchman Bauke Mollema, who started the day in 10th position overall, broke away at the foot of the Col du Portillon, the first of four brutal climbs.
A Movistar soigneur (caretaker), on the climb to hand out drinks to the riders, tangled with the Australian Luke Durbridge(Orica GreenEdge), who fell off his bike, although he remounted to continue the stage.
Vasil Kiryienka of Belarus powered away from the leading group and was first to crest the top of the Col de Peyresourde, but he cracked in the penultimate climb up the Col de Val Louron-Azet. Majka then burst away from the breakaway group as he looked to strengthen his lead in the mountain classification.
Bardet attacked in the descent from the Col de Val Louron-Azet and opened a 30-second gap over Pinot, Nibali, Valverde, Peraud and Tejay van Garderen. Once Bardet had been caught on the final climb, Nibali attacked 5.5km from the finish as Valverde cracked. Peraud was in the Italian's wheel while Pinot, Bardet and Van Garderen chased.
Nibali and Peraud opened a decent gap and Pinot and co limited the damage but could not catch the duo. Valverde, who at one point lagged some 20 seconds behind the Pinot group, was helped on the way by a few Movistar team mates who had been dropped from the morning's breakaway. He fought his way back in the 10.2km ascent and gained a handful of seconds on Pinot. "I had a bad moment, but there were some team-mates to help me," said Valverde. "I managed to limit the damage."
The 24-year-old Pinot now has today's stage to Hautacam to regain time on Peraud and Valverde. "The ascent to Pla d'Adet didn't really suit him, but he likes the climb to Hautacam," said Yvon Madio, his FDJ.fr sports director.