Zander de Bruyn was Somerset's top scorer, with 70 out of 113-6
Young Somerset leg-spinner Max Waller turned the game on another testing wicket at Sophia Gardens as Glamorgan threw away a golden chance of victory.
On 94-4, chasing 113-6, of which Zander de Bruyn made 70, Ben Wright (29) and Mark Wallace (26) looked well set.
But Waller took three wickets in two overs, also holding on to a vital catch to remove Robert Croft at long on.
And, having needed only 15 off three overs, Glamorgan then failed to get nine off the last, buckling to 112-9.
After all the recent headlines about the state of the Cardiff ground, ahead of Glamorgan staging their first Ashes Test match in July, once again it was not an easy pitch to bat on.
Somerset only had two batsmen in double figures, South African de Bruyn hitting almost two thirds of the visitors' runs in his unbeaten 70 off 63 balls.
He hit one six and five fours, sharing an unbroken seventh-wicket partnership with Ben Phillips, who made 13 out of their stand of 46.
Despite Phillips then getting two quick wickets as the home side slumped to 31-4, the panic seemed to be over when Wright and Wallace put on 63 for the fifth wicket.
But, under the Swalec Stadium lights, Glamorgan were to stunningly run out of juice, snatching defeat from the jaws of victory as they surrendered five wickets for nine runs.
After Croft had failed in his attempt to put Omari Banks out of the ground, off the first ball of the next over Dean Cosker followed the former England spinner's example by also holing out in the deep at midwicket.
And then Wright too skied one, getting caught off a leading edge as Waller made one lift.
Even then, last pair David Harrison and Garnett Kruger came close to getting the nine needed off Alfonso Thomas's last over. But, having got that down to three needed to win off the last ball (and two to tie), they could only manage a single.
Glamorgan cricket manager Matthew Maynard: "We didn't apply ourselves at all, did we? It was a target we should have got, our three spinners are better than their three spinners.
"We were cruising it, six wickets in the shed, five an over required off five overs and we committed harakiri - three caught in the deep when singles were required.
"We've got quite a bit of experience down the order there and some daft shots really, and it's one that we've certainly lost rather than Somerset have won."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.