Wing Jared Rosser scored the only try of the first half as his long range score gave Dragons a 13-6 lead at the interval.
Hooker Elliot Dee went over for a second home score before Wales international Justin Tipuric hit back for the visitors and set up a breathless finale.
Jason Tovey nudged Dragons back ahead with five minutes to go before Sam Davies missed a last minute penalty as the home side celebrated a big derby day win.
Interim Head Coach Ceri Jones made one change to the starting line-up that narrowly lost out to Cardiff Blues, with Aaron Jarvis replacing the suspended Lloyd Fairbrother.
The scrum looked in good health in the opening exchanges as a huge set piece won the game’s first penalty and Josh Lewis pointed to the posts from just over halfway.
The home fly half then showed his confidence by booming over a monster kick for the lead after five minutes.
Twice Dragons kicked cleverly in behind to force Dan Evans into hurried clearing kicks, before wing Hallam Amos produced a jinking run to break away in midfield.
Ospreys looked to get into their stride with Scott Williams and Owen Watkin combining and looking wide for the pace of Luke Morgan before George North rattled into contact.
Good line speed in defence was stopping the Ospreys from gaining any early momentum, with skipper Cory Hill, Brandon Nansen and Matthew Screech all prominent.
Harri Keddie then took the battle to the visitors with a big run and won a penalty to relieve the pressure.
Moments later, from the resulting lineout, Ospreys were caught offside and Lewis nudged though the penalty kick.
Sam Davies hit back three minutes later with a kick of his own, after Dragons were pinged at the breakdown.
The opening try arrived in sensational fashion on 28 minutes as huge defence saw Dragons hold firm and then spilled ball allowed scrum half Rhodri Williams clear up field.
The alert Rosser then picked off the bouncing ball, as Morgan and Evans dithered by the touchline, and raced over from halfway to huge cheers.
Sam Davies cut the lead with his second penalty of the game, but Dragons continued to work tirelessly at the breakdown to disrupt ball with Jarryd Sage ripping the ball and centre partner Warren running it clear.
Visiting fly half Davies hit his third penalty at the start of the second half before a sensational kick from Kirchner forced the Ospreys to play from five-metres out.
Rosser then unloaded a huge hit on Morgan to dislodge the ball and Hill kicked ahead and was hauled down just short before Jarvis rattled the ball up to win the penalty.
The home side opted to go for the lineout and it paid off as Nansen was hauled up just short before Dee picked up and dived over. Lewis converted for a 20-9 lead.
The deadly accurate Davies hit his fourth penalty of the afternoon to cut the lead to eight points going into the final quarter of the game.
Wing North then caused alarm as he broke clear and was taken down by Rhodri Williams before a knock on was greeted by growing cheers.
Ospreys hit back as the broke the defensive line through Olly Cracknell with Tipuric on his shoulder to race away and cut the lead to a single point.
Davies hit his fifth penalty of the afternoon for the lead with ten minutes left before Tovey held his nerve with a kick five minutes from time.
And, in a late twist, Davies missed his first kick of the afternoon in the final 60 seconds before Dragons held firm one more time to spark wild celebrations from the home faithful.
05m Lewis p 3-0
19m Lewis p 6-0
22m S. Davies p 6-3
28m Rosser t Lewis c 13-3
32m S. Davies p 13-6
44m S. Davies p 13-9
54m Dee t Lewis c 20-9
58m S. Davies p 20-12
66m Tipuric t S. Davies c 20-19
70m S. Davies p 20-22
74m Tovey p 23-22
Dragons: Zane Kirchner, Jared Rosser, Adam Warren, Jarryd Sage, Hallam Amos (J. Williams 50-60, 70), Josh Lewis (Tovey 64), Rhodri Williams (Knoyle 64); Ryan Bevington (Suter 64), Elliot Dee (Hibbard 60), Aaron Jarvis, Brandon Nansen (Evans 66), Matthew Screech, Cory Hill, Aaron Wainwright, Harrison Keddie (Benjamin 38-40, 70)
Replacements: Richard Hibbard, Gerard Ellis, Dan Suter, Lewis Evans, James Benjamin, Tavis Knoyle, Jason Tovey, Jordan Williams
Ospreys: Dan Evans (Price 66), George North, Scott Williams, Owen Watkin (Allen 57), Luke Morgan, Sam Davies, Aled Davies; Gareth Thomas (Jones 57), Scott Baldwin (Otten 54), Tom Botha (Jeffries 54), Adam Beard, Alun Wyn Jones, Olly Cracknell, Justin Tipuric, James King (Cross 62)
Replacements: Scott Otten, Rhodri Jones, Alex Jeffries, Lloyd Ashley, Sam Cross, Tom Habberfield, Luke Price, Cory Allen
Referee: Dan Jones (WRU)