Swiss cyclist Gino Mäder won the sixth stage of the Giro d’Italia on Thursday for his first victory in a Grand Tour, and Attila Valter took the leader’s pink jersey.

Mäder, who rides for Team Bahrain Victorious, was part of a quartet leading the race up the summit finish and the 24-year-old attacked with three kilometers remaining to cross the line 12 seconds ahead of his fellow escapees.

Egan Bernal was second, just ahead of Daniel Martin and Remco Evenepoel at the end of the sternest test yet of this year's Giro.

Switzerland's Gino Mader celebrates after winning the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021.  (Gian Mattia D'Alberto LaPresse via AP)

Switzerland's Gino Mader celebrates after winning the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021. (Gian Mattia D'Alberto LaPresse via AP)

There were three classified climbs along the 160-kilometer (99-mile) route from Grotte di Frasassi to Ascoli Piceno and the stage was made even trickier by the weather conditions, which were wet and cold.

Valter took over the lead from Alessandro De Marchi. The Hungarian cyclist has an 11-second lead over Evenepoel and 16 seconds ahead of Bernal — two of the favorites for the overall win.

The Giro finishes on May 30 in Milan with an individual time trial.

Belgium's Remco Evenepoel pedals during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021. (Fabio FerrariLaPresse via AP)

Belgium's Remco Evenepoel pedals during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021. (Fabio FerrariLaPresse via AP)

More AP sports: https://apnews.com/apf-sports and https://twitter.com/AP_Sports

Italy's Alessandro De Marchi, wearing the pink jersey of leader of the race, pedals during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021.  (Fabio FerrariLaPresse via AP)

Italy's Alessandro De Marchi, wearing the pink jersey of leader of the race, pedals during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021. (Fabio FerrariLaPresse via AP)

Cyclists pedal during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021.  (Fabio FerrariLaPresse via AP)

Cyclists pedal during the sixth stage of the Giro d'Italia cycling race, from Grotte di Frasassi to Ascoli Piceno Thursday, May 13, 2021. (Fabio FerrariLaPresse via AP)