Davies was just able to hold off Trimble's challenge
Scarlets: (9) 17
Try: B Davies
Pens: C Thomas (4)
Ulster: (8) 11
Pens: D Humphreys (2)
A 60th-minute try from Barry Davies saw a young Scarlets side deny Ulster the chance to go top of the Magners League.
Ceiron Thomas' boot gave the Llanelli side the lead, but the visitors took control with an Andrew Trimble try and two penalties from David Humphreys.
An excellent Matthew Watkins break sent Davies in for a 40-yard try, Humphreys just failing with a long, late penalty.
Thomas got a last-minute penalty, the Stradey Park win ending a five-game league losing streak for the Scarlets.
Ulster's consolation was a losing bonus, taking them to within a point of league leaders Leinster who have a game in hand, having sat out this weekend's fixtures.
Scarlets outside-half Thomas' two penalties were the only scores of a tight and scrappy opening half hour, opposite number Humphreys then replying with a kick for the visitors.
That's a significant win and a significant step forward - I can't credit my players enough
Scarlets director of rugby Phil Davies
Scarlets scrum-half and man-of-the-match Liam Davies took a quick penalty under the Ulster posts, and was unlucky not to be given a penalty try as he was just denied by defenders from an offside position.
Thomas' third successful kick at goal resulted, but the visitors hit back to show their strike power.
Paddy Wallace led a break-out from within the Ulster half, the centre feeding Ireland wing Trimble who just managed to touch down in the corner under a strong challenge from the covering Darren Daniel.
Humphreys missed the difficult conversion, leaving the home side with a one-point lead at the break.
But the Ulster number 10 made amends with his second penalty on 51 minutes, to give his side the lead for the first time.
Watkins' decisive break from inside his own half put the Scarlets back in control, the Wales centre having the strength to shrug off Wallace in midfield.
Watkins fed replacement Davies, who just had the pace to hold off the covering Trimble in the run-in.
Ulster's attempts to fight back were hindered as the Llanelli side repeatedly stole their line-out ball.
Humphreys dropped short with a difficult penalty from the half-way line, and, when the desperate visitors pulled down a well-organised Scarlets maul, Thomas rounded off the scoring.
Scarlets director of rugby Phil Davies:
"They had a full side out, so that's a significant win and a significant step forward - I can't credit my players enough.
"We've worked hard without getting the results recently, so I'm delighted that the players have got their reward.
"There are plenty more games to come at Stradey in the league run-in - there was a fantastic atmosphere here and I have to thank the fans."
Scarlets: Stoddart, Daniel, King, G. Evans, Watkins, C. Thomas, L. Davies, I. Thomas, Gravelle, Manu, Cooper, MacLeod, Bater, G. Thomas, N. Thomas.
Replacements: B. Davies for Stoddart (57), Stuart-Smith for L. Davies (76), J. Davies for Manu (57), Afeaki for Cooper (65), D. Jones for N. Thomas (52). Not Used: Owen, A. Jones.
Ulster: Cunningham, Bowe, Steinmetz, Wallace, Trimble, Humphreys, Boss, B. Young, Shields, S. Best, Harrison, Barker, Ferris, Dawson, Wilson.
Replacements: Maggs for Steinmetz (68), McKenzie. for Humphreys (80), Campbell for Boss (17), J. Fitzpatrick for B. Young (59), Philpott for Shields (73), Caldwell for Barker (59), Harding for Dawson (68).
Referee: Peter Allan (Scotland)