MONTPELLIER, France - Lance Armstrong stormed to within milliseconds of the Tour de France lead on Tuesday after his Astana squad won the team time trial in a tension-filled finish.

The seven-time Tour winner surged from third place to second overall, and more importantly erased all but a sliver of a 40-second deficit to race leader Fabian Cancellara in the fourth stage.

"Boo-YA.

!" Armstrong wrote on Twitter. "Well, what can I say? The team was simply awesome today. Consistent, fluid, mistake-free. We love this event (TTT) and are stoked to win."

It was reminiscent of Armstrong's dominance in the team time trial for the last three years of his string of victories from 1999 to 2005.

For Armstrong, Tuesday's stage was about allying with his Astana teammate Alberto Contador, the top pre-race favourite, to weed out their potential rivals.

Astana clocked 46 minutes 29 seconds for the 39-kilometre ride in and around Montpellier. Ryder Hesjedal of Victoria, the lone Canadian in the race, helped his Garmin-Slipstream team to a second-place finish, just 18 seconds back. The result boosted Hesjedal up to 21st overall from 49th.

The Cervelo Test Team, principally owned by the Canadian Cervelo bike manufacturer, finished eighth.

Because Armstrong came into the day just 40 seconds back of Saxo Bank rider Cancellara, the winner of Saturday's first stage, it came down to split seconds about who got the coveted yellow jersey.

At the last intermediate time check at the 30.5-kilometre mark, Astana was 41 seconds faster than Saxo, putting Armstrong in the lead at that point - and setting up the tense finale.

In the end, the Swiss rider was judged to be a fraction of a second ahead overall, after organizers went back to look over the time from Saturday's individual time trial in Monaco, when results were calculated to thousandths of a second.

"That's Swiss timing," Cancellara said, laughing. "Time is on my side."

After first expressing "a bit of disappointment" on French TV about not capturing the shirt that he knows so well, Armstrong put his performance into perspective.

"That's the way it is. We did our best," he said. "At one point, we thought we had it, but if I look back on our performance ... we were as sound as we could be."

"I have no regrets. I don't look at that and lose sleep or get disappointed," he said at a post-race news conference. "This is a long race, maybe there's one (yellow jersey) in my future."

The potential rivalry between Armstrong and Contador, the Spaniard who won the 2007 Tour, has become a major subtext to the race.

They shelved any such rivalry on Tuesday. Armstrong said he appealed to Contador before the race to work together to distance other contenders.

"My point was to Alberto, 'Look, let's ride perfect, and make this race almost impossible to win for others,"' he said. "And I think we can say that we accomplished that."

Astana dealt a blow to several title hopefuls. Defending champion Carlos Sastre of Spain is 2:44 back; two-time runner-up Cadel Evans of Australia is 2:59 behind; and Giro d'Italian champ Denis Menchov is 3:52 back.

"I think today, the Tour de France is finished for some riders - and we won't go into names - but that's the way that the TTT works now," Armstrong said of the team time trial.

"With no disrespect, it's difficult to make up that time."

After Cancellara, the next four riders are from Astana: Armstrong, with the same time; Contador, 19 seconds back in third; 2004 runner-up Andreas Kloeden of Germany was fourth, 23 seconds back; and Levi Leipheimer of the United States was fifth, 31 seconds behind.

The teams set off one by one at seven-minute intervals in a race against the clock. The stage through sun-baked roads of Montpellier, near the Mediterranean, is among the flattest this year.

Cyclists try to ride single file to cut down on wind drag and take turns in the lead to maximize efficiency and conserve energy. The first five riders record the same times, while laggards get individual times. All teams had nine riders except Quick Step; one member of the Belgian squad quit the race after a crash in Stage 2.

Armstrong said the many tight turns made for "tricky" riding. Three crashes marred the stage start - including one involving Russia's Menchov.

The question now is whether Armstrong's 37-year-old legs can keep up when the three-week race heads on Friday toward three days in the Pyrenees after two mostly flat stages along the Mediterranean.

That's when the Armstrong-Contador rivalry could emerge. They are both far better climbers than Cancellara, one of the world's best time trial riders.

Next up is Stage 5, a 196.5-kilometre ride along the Mediterranean from Le Cap d'Agde to Perpignan.

Armstrong said he's "realistic" about his chance of victory when riders reach the finale on the Champs-Elysees in Paris on July 26.

"It's not going to be easy - I'm not going to get last - but it won't be like 2004, 2005, 2001," he said. "It's going to be a hell of a lot harder than I expected.

"That's as honest as I can say it."