The score was locked at 9-9 until the Ospreys came up with their tries in the space of three minutes. Dan Biggar supplied 13 points with the boot.
Wales wing George North grabbed a late try to seal a losing bonus point for Scarlets, with Rhys Priestland kicking 11 points, but he missed four penalty attempts as well.
The Scarlets approached the game as league leaders with three straight wins, and in contrast the Ospreys were second from bottom after losing all three of their matches.
But the Ospreys, lifted by the intensity of a derby, were far more competitive.
The Scarlets had a try disallowed by the television match official after wing Andy Fenby failed to ground the ball, although he seemed to be high-tackled by George Stowers as he went over the line.
The Ospreys got into good attacking positions but twice knocked the ball on at the crucial moment.
A Joe Bearman high tackle on George Earle, which sparked some pushing and shoving, gave Priestland the opportunity from where he opened the scoring with a third-minute penalty. That was cancelled out four minutes later by a Biggar penalty.
The Scarlets were back in the lead after 13 minutes with Priestland on target from close to halfway. But Biggar responded in kind after 18 minutes.
Biggar missed a penalty after 26 minutes but found the target eight minutes later as the Ospreys led for the first time, and the visitors went to half-time with a 9-6 advantage.
The Ospreys thought they had scored a try three minutes after the break through Dirksen but it was disallowed for a forward pass.
And as the Scarlets worked their way upfield they levelled the scores at 9-9 after 47 minutes with a third Priestland penalty.
The Ospreys brought on Ryan Jones for his first appearance of the season just as Priestland missed a chance to take his side into the lead.
And the Scarlets suffered a blow on the hour mark when their replacement prop Samson Lee was yellow-carded following a collapsed scrum.
Despite being down a man, scrum-half Tavis Knoyle went close to making the left corner and then Priestland hit the post with a penalty attempt.
Back to 15 men, the Scarlets conceded the key try after 72 minutes when Ryan Jones finished off a forward drive from a lineout. The Biggar conversion put the Ospreys 16-9 ahead.
And three minutes later Dirksen was in at the right corner for the second Ospreys try, with Biggar again adding the extras.
The game was effectively gone for the hosts, but small consolation arrived with seconds on the clock as North went over to earn the bonus point and Priestland booted the conversion.
A resilient Connacht made Glasgow work hard before achieving their first win at their new Scotstoun home, triumphing 27-17.
Glasgow were the more enterprising side and significantly each of their four tries, which secured a bonus point, fell to a back three player.
Right winger Sean Lamont grabbed the first and then sent full-back Pete Murchie in for the second.
Canadian international DTH van der Merwe had a second-half brace, while Scott Wight converted two of the tries and kicked a penalty.
However, Glasgow could never shake off the Irish visitors, who had a first-half try from Mark McRea and one in the second period from Nathan White, with Nathan Jarvis converting both and putting over a penalty.
Ulster's game away to Zebre, also scheduled for Friday, was called off following the death of player Nevin Spence the previous weekend.
- Rhys Priestland
- Dan Biggar