Williams had already headed a good chance over when his misplaced back-pass caught goalkeeper Dorus de Vries off guard to hand the Rams a comical seventh-minute lead.
The Wales international was having an afternoon he would not forget anytime soon as he then headed against the crossbar at the right end.
Steven Davies then showed him how it is done with a header from Conor Doyle’s corner shortly after the restart to extend Derby’s lead.
Substitute Darren Pratley headed Swansea a 65th-minute lifeline and Stephen Dobbie hit the bar soon after, but Derby held firm to clinch only their third win in 19 Championship matches.
The victory, the Rams’ first over the Welsh outfit since 1986, made it three games without a win for second-placed City who are suffering a case of promotion jitters at a crucial stage in the campaign.
Derby boss Nigel Clough recalled skipper Robbie Savage, Alberto Bueno and Davies for the clash, while Swans counterpart Brendan Rodgers kept faith with the same XI who started Tuesday’s 1-1 draw at home to Watford.
And it was centre-back Williams who was at the centre of two key incidents in the opening exchanges.
First he headed a glorious opportunity over the bar from merely yards out and then he misjudged a pass back to De Vries from inside the area and, despite the best efforts of the Dutchman who rushed across his goal, the ball crossed the line to hand County an effortless lead.
The advantage seemed to breathe confidence into the hosts and a 20th-minute free-kick caused all sorts of problems in the visiting box before Jamie Ward’s header was turned around a post by De Vries.
Williams was already centre stage at Pride Park before he then headed against the crossbar midway through the first half.
Swansea started to get a foothold as the opening 45 minutes wore on and Dobbie fizzed an effort narrowly wide from 20 yards.
The well-travelled Scot then came within inches of laying on an equaliser for Scott Sinclair who just failed to connect with his cross.
Swans boss Rodgers turned to midfield duo Pratley and Leon Britton at the interval.
And the fresh impetus saw the visitors dominate proceedings at the start of the second half, only for the Rams to land a sucker punch in the 54th minute.
Doyle, a 50th-minute replacement for Paul Green, sent over a corner and Davies did well to head the ball home under pressure.
De Vries kept the hosts in it with a great stop from Davies before Pratley handed City hope with a 65th-minute header which owed much to the hesitancy of Derby’s on-loan goalkeeper Frank Fielding.
Dobbie connected with the woodwork just minutes later before Pratley fired just wide as Swans applied plenty of pressure.
Derby substitute Theo Robinson wasted a glorious chance to make it 3-1 but the miss proved inconsequential for the victorious hosts.