MARSEILLE, France — Mark Cavendish finally shook off an illness and a drop in form to earn his 24th career stage win at the Tour de France on Wednesday and close the gap on rival Peter Sagan for the top sprinter’s green jersey.

The British sprinter relinquished his green jersey to Sagan last year and trails the Slovak again. But by winning the fifth stage, Cavendish closed within 35 points of his rival, who finished third in the crash-marred trek to the southern seaport of Marseille.

‘‘Now the pressure’s off and hopefully it has started the ball rolling,’’ Cavendish said.

Australian veteran Simon Gerrans kept the overall leader’s yellow jersey by avoiding two crashes — the first as riders neared the end of the stage and the second moments after Cavendish had comfortably beaten Norwegian Edvald Boasson Hagen in their dash to the line.

Cavendish made a poor start to the Tour while he struggled with a cold. He watched his Omega Pharma-QuickStep squad lose the team time trial Tuesday by less than a second to Gerrans’s Orica Greenedge squad.

‘‘I'm still suffering a bit. I'm a lot better but still not 100 percent,’’ Cavendish said. ‘‘Finally, after the disappointment of the first stage and [losing by] less than a second yesterday, we've got the account open.’’

With a few hundred meters to go, Cavendish stayed behind his teammate Gert Steegmans’s wheel and got into a perfect position to hold off Boasson Hagen.

‘‘To be fair, today the sprint wasn’t too difficult for me,’’ Cavendish said. ‘‘If I'd have lost that today, I would have let the guys down.’’

The 84-year-old Andre Darrigade, who won 22 Tour stages as a sprinter, warmly greeted Cavendish after his win.

Cavendish needs one more stage win to tie Andre Leducq for third on the all-time list of stage winners at the 110-year-old race — which is celebrating its 100th edition — and he could do that on Thursday as Stage 6 again favors sprinters.

That would put him within range of Bernard Hinault’s 28 wins, the second-highest total after Eddy Merckx’s imperious record of 34.

‘‘You have to show the Tour de France the respect it deserves. One stage [win] on the Tour de France makes a rider’s career, let alone one stage every year,’’ Cavendish said. ‘‘But to set any goals, it does one of two things: It sets you up to fail or puts a limit on what you want to achieve.’’

While Cavendish was raising his arms in triumph, behind him about a dozen riders hit the tarmac on the day’s second crash.

American rider Tejay van Garderen was one of those involved in the pileup.

‘‘I was grabbing a bottle from [BMC teammate] Steve [Morabito] and then we hit this left corner and people hit the brakes pretty hard,’’ van Garderen said. ‘‘I had one hand on the bars [and] lost control. Completely my fault, just a lack of focus, but nothing bad. Just a couple more cuts, but no broken bones.’’

Gerrans is only the sixth Australian to wear the yellow jersey — the first was Phil Anderson in 1981 — and his Orica Greenedge took the start line with yellow helmets on to mark the occasion.

Gerrans will hope to keep it after the sixth stage on Thursday. It’s a flat 110-mile route from Aix-en-Provence to Montpellier. The race heads into the high mountains for the first time in the eighth stage on Saturday from Castres to Ax 3 Domaines in the Pyrenees.

. . .

American rider Ted King fought back tears as the peloton rode away without him because he was too injured to complete the previous stage in regulation time.

Some competitors felt race regulators were overzealous in excluding the Cannondale rider for being a fraction too slow in the team time trial.

‘‘Rules are rules, but it is a little bit tough, isn’t it?’’ said Richie Porte of Team Sky. ‘‘It does seem rough.’’

‘‘I'm shredded,’’ King said.

Cannondale said King missed the cut by just seven seconds. Tuesday’s team race against the clock on a 15½-mile course through Nice
was the fastest in Tour history, which made it harder for King, who separated his left shoulder in a crash in Stage 1.

‘‘I would have hoped for more empathy given the scenario,’’ King said. ‘‘I'm not looking for generosity; I'm not looking for a hug from [race organizers] ASO. I'm looking for some empathy, some understanding.’’