Rinaldo Nocentini of Italy earned the yellow jersey for the second straight day by finishing in a pack with Armstrong and his Astana teammate Alberto Contador. The 2007 Tour winner is six seconds back, with Armstrong eight seconds back.
Armstrong went straight to the team bus after the stage and did not speak to reporters. He posted on Twitter: "St8 done. Tough but not 2 challenging. Had antidoping control AGAIN. Couldn't pee so it took forever. Sucked! Now I'm starting to wonder tho"
Teammate Levi Leipheimer is 39 seconds off the pace in fourth place overall.
Nocentini almost lost his yellow jersey when the main race favorites including Armstrong and Contador left him behind in the last of the climbs. He credited an escort from his AG2R La Mondiale teammate Stephane Goubert for helping him catch up.
"I had been dropped," said Nocentini, a 31-year-old riding in his first Tour. "To him, I say 'thank you' for helping me hang on to the yellow jersey."
Before the start, Leipheimer tweeted: "Today's stage starts off going uphill for 20 miles!! That's a rude awakening, plenty of riders will be looking to get in the breakaway."
He certainly was right.
Two-time Tour runner-up Cadel Evans, a pre-race favorite, was among those to attack on the first climb, the Envalira Pass, at the 14.6-mile mark. He and others built a lead on the pack of about 2 minutes, but the Australian was reeled in after about 39 miles.
Sanchez, who won the Paris-Nice stage race in March, led a four-person breakaway toward the finish line. He looked skyward and tapped his chest after crossing just ahead of France's Sandy Casar and Mikel Astarloza of Spain. They clocked 4 hours, 31 minutes, 50 seconds for the 110-mile trek along three big climbs from the Pyrenean principality of Andorra to Saint-Girons.
"You need to have luck," said Sanchez, who won a Tour stage last year. He dedicated the victory to his older brother, Leon, who died in a quad bike accident four years ago.
The victory for Caisse d'Epargne rider Sanchez was a boost to his team. Oscar Pereiro, the 2006 Tour champion, quit the race due to fatigue and the team's star rider, Alejandro Valverde, is not in the Tour because of an Italian doping probe.
Vladimir Efimkin, who was reeled in by Sanchez after a failed solo breakaway, finished the stage in fourth place, while the main pack trailed 1:54 behind.
"That was a really long, hard climb," said Christian Vande Velde of Garmin-Slipstream, who was 1:24 behind the yellow jersey and eighth overall.
Among the other favorites, Andy Schleck of Luxembourg is 1:49 back in ninth, defending Tour winner Carlos Sastre of Spain is 2:52 back in 16th, and Evans is 3:07 behind in 18th place.
Riders face a third and final day in the Pyrenees on Sunday, a 100-mile course from Saint-Gaudens to Tarbes via the famed Tourmalet Pass, one of the toughest climbs in pro cycling.
The three-week race ends July 26 in Paris, with the Alps, a final individual time trial and the dreaded Mont Ventoux awaiting in the last week.