Mark Cavendish won the final stage of his last Giro d’Italia to spark scenes of huge emotion in Rome as Primoz Roglic confirmed his overall victory.

Cavendish, who announced on the second rest day of this race that this season would be his last, made it look easy as he opened up several bike lengths over Alex Kirsch and Fernando Gaviria even before a crash on the final approach split the bunch.

It was a 17th career Giro stage win for the 38-year-old Manxman, who kept alive his record of winning at least one stage every time he had taken part in the Italian Grand Tour.

It was also Cavendish’s first win of the season and first with the Astana-Qazaqstan team, a timely confidence boost as he now turns his attentions to the Tour de France and his bid to take the stage win record there outright.

“I’m super happy,” Cavendish said. “It was a long, hard slog to get here to the end of this Giro. We’ve been close a couple of times before but my boys did an incredible job and my friends were incredible.

“I just had some great friends today, some long-time friends and it’s pretty emotional to be fair.”

The friend at the forefront of Cavendish’s mind was his one-time housemate Geraint Thomas. On Saturday the Welshman had his heart broken when Roglic took 40 seconds from him to snatch the pink jersey and seal overall victory in this race by 14 seconds, the fourth smallest margin of victory in Giro history.

But the Ineos Grenadiers rider put this disappointment to one side as he helped Astana’s short-handed lead-out train for Cavendish, shouting to Luis Leon Sanchez to get on his wheel as he powered to the front of the peloton with two kilometres to go.

There was an emotional hug between the pair of them after the finish.

“I was just there and I saw he only had Luis with him, so I thought I’d help a brother out,” Thomas said on Eurosport.

Victory makes Cavendish the oldest ever stage winner at the Giro, and comes 15 years after he took his first back in 2008.

“To win here in Rome, it’s beautiful,” Cavendish said. “That’s a bucket-list sprint, to be able to do it outside the Colosseum, I’m so happy.”

Italy Giro Cycling
Primoz Roglic celebrated his overall victory in the race (Fabio Ferrari/AP)

The sprint came at the end of a day which saw Roglic celebrate his fourth Grand Tour win – his Giro title goes along with three from the Vuelta a Espana – with team-mates and rivals on the road into Rome before the peloton took on seven laps of a circuit past the Eternal City’s famous sights.

“I definitely enjoyed the moment,” Roglic said. “I also enjoyed everything that happened yesterday. It’s always nice when you win but just this energy from yesterday and riding today in this spectacular city, surrounded by all these things, it’s super beautiful and I enjoyed it a lot.

“Every win is special and I am grateful to be able to achieve this. It will stay in my memories for the rest of my life.”

And it said everything about the character of Thomas that his own disappointments did not stop him revelling in the success of Cavendish.

“It’s been good,” Thomas said of the Giro as a whole. “I had to stop reading my text messages yesterday because I was starting to well up. It’s been a great race, the boys have been amazing and I’ve really enjoyed it.

“It might be 37 but I feel at least 27.”

Italy Giro Cycling
Geraint Thomas wants to continue into next season (Fabio Ferrari/AP)

Thomas will be out of contract at the end of the year but has indicated he wants to continue.

“I still really enjoy it,” he said. “I’m still competitive, I still love racing and I enjoy the argy-bargy of a sprint sometimes. I’ll just keep doing it as long as I love it.

“I’ll try and sort out the future in the next couple of weeks. I’m not going to do more than two (years) I don’t think but saying that, I said I wouldn’t go on after this year so….”