There were plenty of tries, Williams doing most of the damage, but Cardiff could and perhaps should, have won by more.
Martyn Fowler's side had led 15-7 at the break with early scores from Rory Watts-Jones, Dan Fish and Williams. Influential young centre Tyler Morgan had replied for Newport with Geraint O'Driscoll converting but the interval score line was not a fair representation of how the game had gone.
The second half saw Johnathan Edwards and Williams extend Cardiff's lead only for Newport to hit back via wingers Ashton Hewitt and Elliot Frewen. In the end though, it wasn't enough and Williams' third sealed it in the final few minutes.
The first quarter had seen Newport give a lesson in how not to start well. Some poor tackling, indiscipline and general lack of appetite saw Cardiff pull well clear through tries from Watts-Jones, Fish and Williams. In truth, it was poor stuff from the Black and Ambers as the home side ran riot.
No. 8 Watts-Jones opened the scoring by crashing over from close range with the second a particularly poor reflection on Newport. Cardiff hooker Aaron Fowler easily intercepted a wild Newport pass and without the pace to make it to the line, hacked ahead. Newport's Hewitt looked to have the danger covered but the Wales Under 18 wing dawdled in the dead ball area, allowing Fish to pounce and dot down for Cardiff's second of the day.
A terrible start was then made worse for Newport as flanker Sam Waldron was yellow carded, Cardiff taking advantage with the ball again spread wide for Williams to finish in the corner.
The fierce rivalry between Cardiff and Newport dates back almost 400 years but at this stage, the game barely resembled a contest. Newport's only consolation was that Ceiron Thomas looked to have left his kicking boots at home, the Cardiff fly half missing all three of his conversion attempts as well as a penalty effort.
After a horror first quarter, Newport did begin to stem the tide and although there was initially no breakthrough, they did bounce back just before the break. Young centre Morgan was the scorer and when O'Driscoll converted, the visitors were 15-7 down at the break.
The half time score was certainly flattering for Newport but as the second 40 got underway, Cardiff resumed their dominance. Skipper Edwards finished superbly in the corner to end a free-flowing move before Williams waltzed through some static defence for his second. Joe Griffin, who had taken over kicking duties from Thomas, converted the second of those scores.
It seemed like Cardiff would now pull clear but again, Newport found a response. Fish was yellow carded at the contact area and with a man extra, the Black and Ambers took advantage with Hewitt crashing through a Garyn Lucas tackle to score.
O'Driscoll missed the conversion but it was Newport who were now on top. After making a string of substitutions, Cardiff were now struggling to string any possession together and it wasn't long before Frewen crossed for Newport's third.
It meant the final 10 minutes was nervier than it should have been for Cardiff, but they held on with Williams sealing his treble late on.
In the other Premiership game to take place on Saturday, Llandovery were given a scare by Neath at Church Bank. The home side eventually ran out 34-31 winners in a high-scoring encounter to maintain their impressive home record so far this season.