The stage had begun in the Bridlington rain, and it was a day of tough riding, the 135km (85 miles) taking in parts of the North York Moors and up to Whitby, before heading back down to Scarborough.
Team Ineos and CCC Team opened up the race as a lead group split from the peloton, on a stage that included five tough climbs.
Chris Lawless of Team Ineos looked set to take victory at the finish line, which, due to the predicted weather conditions had been moved to beneath the castle headland, as it was in 2017.
But Alexander Kamp, of Denmark, snatched the win as the crowd roared on the riders.
Lawless has the overall race lead ahead of Sunday's final stage.
Star names Chris Froome and Mark Cavendish finished 11th and 65th respectively.
Earlier, the finish-line crowds were relieved that the rain kept off, although there was an occasional soaking from waves and spray on Scarborough's Royal Albert Drive.
Lauren and Kylie Brooks, from Barnby Dun, Doncaster, have visited Scarborough on each of the five runnings of the race, and said it was the best place to watch it. "We've seen all of this year's stages, and got soaked on the other days, but today was really special, the finish is just great."
Earlier, Marianne Vos won the women's title, the second and final day of that race following the same course as the men.