The Netherlands all-rounder's partnership of 213 with Dean Elgar (68) at Taunton was a sixth-wicket record for the county in a List A game.
And he hit a six and 24 fours in his 122-ball innings - the first limited-overs hundred of his career.
Ben Foakes had earlier top-scored for Surrey with 92 as they posted 290-8 from their 50 overs.
It looked like the match was theirs for the taking as Jade Dernbach (3-46) and Sam Curran (2-52) cut through Somerset's top order with the new ball.
Opener Steven Davies was among their victims, departing lbw second ball to Dernbach for a duck against his former club.
But 32-year-old Van der Merwe, who made 209 off 166 balls in a four-day game against Oxford MCCU earlier this month, met the crisis head-on with a series of audacious strokes.
His first 50 took 44 balls and his second just 33 as he reached his century with back-to-back boundaries off Tom Curran.
Elgar was eventually bowled by Scott Borthwick in the 37th over, but by then the pair had already beaten the county's previous sixth-wicket record of 209 between Lewis Gregory and James Hildreth against Durham in 2014.
He was replaced in the middle by Gregory, who lifted a ball from Dernbach over the wicketkeeper's head for four as the home side - beaten in their opening two Championship matches - won with 6.1 overs to spare.
Somerset all-rounder Roelof van der Merwe told BBC Sport:
"Being 22-5 and getting over the line, it's an unbelievable feeling, and it's going to help the team going forward.
"We knew 290 was an alright score, but it was a good wicket and if two batters could get in (we had a chance), and that's what Deano and myself did, and we got over the line.
"It was one of those (innings) where you nick a few past the keeper, and a few inside edges went my way today, you take it as it comes."
Surrey wicketkeeper/batsman Ben Foakes told BBC Radio London:
"It was a freakish game. With 290, we thought we were above par and in with a good chance, and when they were 22-5, you think you've pretty much got it wrapped up.
"It was one of the best knocks I've seen and in those circumstances, you've got to take your hat off to him and say well played.
"Him and Dean Elgar put that big partnership on, and kept them up with the run rate, which was the most important thing.
"They were never behind with that, so they didn't have that pressure, and he just kept going and never gave a chance."
Roelof van der Merwe hit an astonishing unbeaten 165 as Somerset recovered from 22-5 to beat Surrey in the One-Day Cup.