TOURS, France -- Marcel Kittel overtook Mark Cavendish at the line to win the 12th stage of the Tour de France on Thursday, while Chris Froome avoided a late crash to protect his big lead.

Cavendish attacked first but Kittel's late burst got him to the finish first by half a wheel to earn his second stage win in three days, and third of this race.

"As we say in Germany, good things come in three," Kittel said. "It was a real sprint today, that's why I'm so happy."

German riders have won five stages so far -- with Tony Martin winning Wednesday's time trial and Andre Greipel also winning a sprint stage. Beating Cavendish for pure speed, a rare feat, will further boost Kittel's confidence.

"It's a big achievement for me, my team, and for German sprinters as well," Kittel said.

It has been a nervy Tour so far and about 20 riders were caught in a crash near the end. Froome's Sky teammate, Edvald Boasson Hagen, broke his right shoulder blade and dropped out of the tour. Froome was close enough to "hear the crash" but just far ahead enough to avoid it.

"It's always like that at the end before a sprint," Froome said. "It's scary for everyone."

Froome still leads Alejandro Valverde by 3 minutes, 25 seconds and is 3:54 ahead of two-time former champion Alberto Contador.

"At the moment I'm trying to save as much energy as possible for Mont Ventoux at the end of the week and then the Alps next week," said Froome, who dominated the first big mountain stage of the race in the Pyrenees last Saturday.

"Mont Ventoux will be the next really hard day for the general classification," he added.

While Froome is firmly on track to become the second British rider to ever win the race -- Bradley Wiggins won it ahead of Froome last year -- countryman Cavendish has had a frustrating race.

The Tour's best sprinter two years ago, he looked well set to clinch his 25th career stage win as his Omega Pharma QuickStep teammate Gert Steegmans got him in a great position.

Surprisingly, Cavendish did not have the legs to hold on.

"I could jump onto his wheel and it worked out really well for us," Kittel said. "I'm very proud of that victory. I showed today that I can beat the best sprinters."

Cavendish did not look for excuses.

"I can go back and look over it but he was just faster," he said. "(My teammates) delivered me at the right time. I was just beaten by a better guy."

Peter Sagan finished third and holds a comfortable 96-point lead in his bid to retain the best sprinters' green jersey. Cavendish was second, Greipel third and Kittel fourth.

The peloton rolled through vineyards and alongside the Chinon forest on a 218-kilometre (135.5-mile) route from Fougeres to Tours in the Loire valley, a picturesque region dotted with imposing chateaux such as the spiral-towered Chateau d'Usse, which dates from the 11th century, and the 16th century Chateau d'Azay-le-Rideau, which rests on the water.

Keen to keep their riders near the front of the main pack and limit the risk of crashes, Froome's Sky and Contador's Saxo-Tinkoff squads took turns pushing from the front.

"That is the best position to be in because there are crashes everywhere," Froome said. "I did hear the crash behind me."

Saxo-Tinkoff tried to pull away with about five kilometres (three miles) left, but Ian Stannard helped Froome catch them.

Moments later, Norwegian rider Boasson Hagen's tour ended when he was the worst affected in a pile-up of 20-odd riders who were sent flying backwards, upwards and sideways off their bikes.

"It's a real shame for Edvald and a setback for the team," Sky manager Dave Brailsford said. "But ultimately we're still confident that, with the riders we've got left, we can pull together and see the race through."

Then, with the finish in sight, Froome survived a delicate moment when he appeared to be nudged by Tom Veelers.

"I must have hit 10 guys on the run-in today," Froome said. "That's the way it is."