Williams’ eighth goal of the season six minutes from time was enough to condemn second-placed North End to their second successive defeat after a run of eight straight wins.
Ben Gladwin’s right-wing cross was deflected into the path of Williams who planted a bullet header into the roof of the net.
The goal maintained Swindon’s record of scoring in every home game since February and propelled them to third in the table, two points behind their opponents.
It was Preston who came closest to breaking the deadline in the first half when Joe Garner’s early header was well saved by Swindon goalkeeper Wes Foderingham.
Swindon took the initiative after the interval with Preston stopper Jamie Jones denying Massimo Luongo and Michael Smith.
Williams almost sealed the points in stoppage time when he seized on Luongo’s pass before darting beyond two defender and firing over the crossbar.