Jan Tratnik won stage 16 of the Giro d'Italia from a breakaway as Joao Almeida used a late attack to add a couple of seconds to his lead in the pink jersey.

With gradients of 20% inside the final two kilometres, Deceuninck-QuickStep’s Almeida rode away from Wilco Kelderman of Team Sunweb to take his overall lead to 17 seconds, two days after Kelderman took 41 seconds out of him on the road to Piancavallo.

That all happened almost 13 minutes after Bahrain-McLaren’s Tratnik beat Ben O’Connor of NTT Pro Cycling up the final climb to secure his first Grand Tour stage win.

The rolling 229km stage from Udine to San Daniele del Friuli was custom-designed for a breakaway and duly attracted a 28-strong group which went up the road and was handed a 15-minute advantage by a disinterested peloton.

The group began to splinter with more than 60km to go, first as EF Education First’s Ruben Guerreiro went clear and then as Tratnik and Astana’s Manuele Boaro overhauled him.

"The last three kilometres I was already on the limit but when I saw 500m from the finish I saw my girlfriend and got some extra energy and I flew to the finish line"

Tratnik went solo on the second of three ascents of the Monte di Ragogna, building a lead of 45 seconds before O’Connor set off after him, making the catch as they reached the summit for the final time with 13km left.

But that effort told in the legs as Tratnik accelerated away inside the final 600m for a comfortable win not far from the border with his Slovenian homeland.

"Today was special because it was really close (to home)," he said. "In the finish my brother and my girlfriend were there.

"The last three kilometres I was already on the limit but when I saw 500m from the finish I saw my girlfriend and got some extra energy and I flew to the finish line."

Almeida began his attack at a slightly earlier point as the peloton arrived, but it had the same effect as Kelderman, his team-mate Jai Hindley and the Ineos Grenadiers’ Tao Geoghegan Hart, the Londoner now fourth overall, lost his wheel by the summit to concede time.

"I was feeling good," Almeida said. "Sometimes the best defence is attacking and that’s what I did today. I tried, why not? When it’s steep like this, everyone’s spent energy so I think it was good."

Hindley’s deficit in third is two minutes and 58 seconds, with Geoghegan Hart still one second off the podium.

Geoghegan Hart’s team-mate Ben Swift took fifth place on the stage after being active in the breakaway.