Sergio Henao was cruelly denied his first victory for Team Sky after the Colombian and team-mate Ian Stannard lit up the finale of stage six of the Tour de Pologne.
Henao put in an impressive attack on the final climb up to the finish in Bukowina Tatrzanska and seemed set for a fine win as he opened up a large gap on the chasing pack.
But Moreno Moser (Liquigas-Cannondale) came from a long way back to edge him out on the line, with Michal Kwiatkowski (Omega Pharma-QuickStep) coming home in third.
Henao also attacked on the penultimate climb of the day after being set up by British champion Stannard, who had been a part of the day's breakaway.
Despite his exertions in the breakaway, Stannard managed to animate the closing stages as well, with his final move being reeled in at the start of the last ascent.
The result moves Henao up into third on general classification, 16 seconds off the lead. Moser is back in the leader's jersey by five seconds ahead of Kwiatkowski due to the bonus seconds he gained for winning the stage.
Stannard, Roman Kreuziger (Astana), Tomasz Marczynski (Vacansoleil-DCM), Tom Jelte Slagter (Rabobank) and Bartosz Huzarski (Polish National Team) had earlier formed a breakaway as the riders embarked on a 191.8 kilometre trip.
Slagter was the first rider to drop off and was caught by the peloton well before the finish, while the remaining four forged on ahead on the tough finishing circuit.
Team Sky's Alex Dowsett pulled out of the race during the stage, while the rest of the team focused on setting things up for Henao.
As the peloton closed in on the breakaway, Henao flew across to the wheel of Stannard, who found hidden reserves to tee up the Colombian for his attack up the ultra-steep penultimate climb.
Behind Henao the peloton was splitting up, but several riders managed to bridge across on the subsequent descent, with Stannard somehow having the energy to put in another dig.
The British champion was caught at the start of the final climb, allowing Henao to put in a second attack on the steepest section.
As the climb flattened off Henao kicked again and it looked as though he had the stage sewn up, but Moser showed an incredible turn of speed to come around the 24-year-old at the last possible moment.
Afterwards Sports Director Nicolas Portal said: "It's such a shame for Sergio that he couldn't get the win because he and the whole team were brilliant throughout the day.
"The main aim was to try and win the general classification with Sergio by making the stage as hard and selective as possible so that he could get a gap on the rest.
"The guys did everything perfectly, the plan was first to get someone in the breakaway and Ian was outstanding and so strong - he was on the front for so long and then tried to help Sergio when he attacked.
"It was great work from the whole team though - Swifty for example was in the points jersey and yet pulling them up the climbs!"
Talking through the agonising finish, Portal added: "Even when it had come back together, Sergio then did everything he could to win the stage - he first attacked on the steepest part of the climb and then he kicked again at the end.
"He was unbelievable and has again shown everybody just what a good rider he is - I'm very proud of all the riders."
Looking ahead to Monday's final day, Portal added: "Tomorrow is a flat stage so we'll try to work for Swifty and I know he's very motivated to keep his points jersey."