Cavendish now heads home to prepare for the Tour de France
Mark Cavendish signed off from the Giro d'Italia in style as he sprinted to victory in Stage 12 to secure his second win of the 2011 edition.
Cavendish escaped a late pile-up which split the field and hit the front with 350m left.
He held off Davide Appollonio's charge with Alessandro Petacchi third.
The Giro now tackles the mountains as it moves into the Alps and Cavendish confirmed: "I'm going home tonight to recuperate for the Tour de France."
The Isle of Man rider added: "This was the last sprint in this Giro and it's really big for me and the team - we controlled the entire stage, the team did an incredible job.
"It was a successful Giro for me and the team."
Cavendish said he had managed to avoid the late crash because his HTC-Highroad team had predicted there could be problems.
"We had seen before the stage, in the route-book, that it might be difficult, we knew we had to be close to the front, and we got through it OK," he said.
Alberto Contador retained the pink jersey of the overall leader.
Four riders - Miguel Minguez Ayala, Davide Ricci Bitti, Stefan Clement and Michal Golas - broke clear of the peloton after only four miles.
The quartet led by more than three minutes at one point but were caught by the pack with nine miles (14 km) to go.
HTC-Highroad set the pace for the final few miles and when the crash occurred just outside the final kilometre Cavendish was safely out of harm's way near the front, lying third in a train of three HTC riders.
Within sight of the line lead-out man Mark Renshaw peeled off and Cavendish powered on, although Appollonio briefly looked like he might get on terms.
Stage 13 on Friday is a 104m (167km) leg from Spilimbergo to Grossglockner, Austria, featuring four climbs, including an uphill finish.
Saturday's Stage 14 is perhaps the toughest of the race, a 130m (210km) leg from Lienz, Austria, to Monte Zoncolan.
It features five climbs, plus the Crostis descent, and ends with one of the toughest climbs in Europe, Monte Zoncolan.