Marcel Kittel beat Britain's Ben Swift by the width of a wheel to win stage three of the Giro d'Italia in Dublin.
Team Sky rider Swift looked set to win his first Grand Tour stage, but Kittel's terrific burst of speed saw him claim a second successive victory.
"I thought I'd lost because I wasn't in a good position," said the German, who was celebrating his 26th birthday.
Australia's Orica GreenEdge rider Michael Matthews finished in the peloton to retain his overall lead.
A bunch sprint was expected in the capital of the Republic of Ireland at the end of a 187km race that started in the Northern Irish city of Armagh.
Kittel, who had comfortably won a similar finish in Belfast on Saturday, was favourite to notch a second victory but as the race entered the final kilometre, the Giant-Shimano rider was off the pace and without a lead-out train of team-mates.
Team Sky's Edvald Boasson Hagen led the charge for the line, with team-mate Swift in his slipstream, and when the Norwegian pulled to one side in the final 200m it looked like the Yorkshireman would win.
However, Kittel came from 20m back in the final 100m, timing his sprint to perfection, to pass Swift in the final five metres.
"When I could see the finish line after the final corner I gave it everything and it was really close but I just concentrated on the line and managed to come past everyone," said the German.
"It is extra special to win on your birthday and I must thank my team-mates for the work they did for me again."
Italy's Elia Viviani, who had been expertly led out by his Cannondale team-mates, took third place.
Another damp and blustery day made for tough racing and there were several minor crashes on the slippery roads.
Race leader Matthews survived a spill, while his compatriot and Orica GreenEdge team-mate Cameron Meyer looked dazed and was clutching his jaw after hitting the tarmac with around 35km remaining.
The riders will have a rest day on Monday while the race moves to Italy for the remaining 18 stages of the three-week event, which ends in Trieste on 1 June.
Tuesday's fourth stage is a 121km race from Giovinazzo, which ends with several circuits of Bari and is again expected to end in a bunch sprint finish.
Stage three result:
1. Marcel Kittel (Ger/Giant) 4:28:43"
2. Ben Swift (GB/Team Sky) same time
3. Elia Viviani (Ita/Cannondale)
4. Davide Appollonio (Ita/AG2R)
5. Nacer Bouhanni (Fra/FDJ.fr)
6. Edvald Boasson Hagen (Nor/Team Sky)
7. Roberto Ferrari (Ita/Lampre)
8. Edwin Avila (Col/Colombia)
9. Giacomo Nizzolo (Ita/Trek)
10. Tyler Farrar (US/Garmin)
1. Michael Matthews (Aus/Orica) 10:06:37"
2. Alessandro Petacchi (Ita/Omega Pharma - Quick-Step) +8"
3. Daniel Oss (Ita/BMC Racing) +10"
4. Luke Durbridge (Aus/Orica) +14"
5. Ivan Santaromita (Ita/Orica)
6. Svein Tuft (Can/Orica)
7. Pieter Weening (Ned/Orica)
8. Cameron Meyer (Aus/Orica)
9. Rigoberto Uran (Col/Omega Pharma - Quick-Step) +19"
10. Gianluca Brambilla (Ita/Omega Pharma - Quick-Step)