Williams's first came via the quick hands of fullback Lee Byrne after the Dragons fluffed a line-out close to their own line. The Ospreys' edge in the set pieces against an under-strength Dragons side had already opened the door for No.8 Andy Lloyd to canter over from the back of a scrum.
The Dragons, the subject of a takeover bid, threatened to make a fist of it with two penalties before half-time and wings Jimmy Norris and Gareth Wyatt both went close.
Yet a floodlight failure in one corner of the old ground early in the second half also saw the lights go out of the Dragons' resistance. A moment of opportunism saw Williams sneak in from his own speculative kick with centimetres to spare as Dragons Martin Thomas and Alex Walker stood still, expecting the ball to bounce out of play.
Filo Tiatia grabbed the vital bonus point from another line-out blunder to send the Ospreys up to second in the table, a point behind league leaders Leinster.
Shaun Connor slotted a late penalty with points difference in the table in mind, only for Gareth Maule to grab a deserved consolation try for the Dragons six minutes into injury time.
Try: G Maule
Con: A Thomas
Pens: A Thomas (2)
Tries: S Williams (2), A Lloyd, F Tiatia
Cons: J Hook (2)
Pen: S Connor