VICENZA, Italy (AP) -- Alberto Contador extended his overall lead ahead of Fabio Aru to 17 seconds while Philippe Gilbert won the rainy 12th stage of the Giro d'Italia on Thursday.
It all came down to a brief climb in the final kilometer.
Gilbert, the 2012 world champion, attacked and surged ahead of a couple breakaway riders to cross the line alone. The Belgian rider with BMC clocked nearly 4 1/2 hours over the 190-kilometer (118-mile) leg from Imola to Vicenza, which featured a hilly finish.
"This was my last chance to win a stage," said Gilbert, who is not a strong enough climber to compete in the big mountain stages. "This was a stage I came to inspect after the Milan-San Remo, so I knew every aspect of the last 70 kilometers. These types of finishes are my specialty."
Contador crossed second, three seconds behind, and gained a six-second bonus. Diego Ulisse was third.
Aru finished outside the top 20, 11 seconds behind Gilbert.
"My legs are getting better every day," said Contador, who dislocated his shoulder in a fall on the final sprint of Stage 6. "I've got a lot of confidence. ... I saw (Aru) was having a tough time keeping up so I went to the front."
A two-time Tour champion, Contador won the Giro in 2008 and was also triumphant in Milan in 2011 but was stripped of that title for testing positive in the 2010 Tour.
In the overall standings, Contador now leads Aru by 17 seconds. Aru's Astana teammate Mikel Landa is third, 55 seconds back.
"I had some trouble because I wasn't able to eat," Aru said. "I didn't have enough sugar. It can happen to anyone."
Stage 13 Friday is an entirely flat 147-kilometer (91-mile) leg from Montecchio Maggiore to Jesolo -- in the Venice area.
Stage 14 Saturday could be the most important leg of the race, an unusually long individual time trial at 59.4 kilometers (36.9 miles) from Treviso to Valdobbiadene.
The 98th Giro ends on May 31 in Milan.