The Robins forced Portsmouth into some desperate clearances early on. Mustapha Dumbuya knocked James Collins' header off the line after 28 minutes and Alan Navarro followed up with a fierce drive, which was brilliantly stopped at his near post by Pompey goalkeeper Mikkel Andersen.
The visitors made their pressure count just before half-time when Williams unleashed Ritchie, who beat Andersen with a rasping finish to give Swindon the lead.
The visitors doubled their advantage in the 55th minute when Williams turned Pompey defender Gabor Gyepes inside out, before lashing a superb shot high across Andersen.
Pompey's Izale McLeod raced forward to craft a golden opportunity for skipper Brian Howard after 83 minutes, but his effort was smuggled behind.
Howard floated the resulting corner across and Darel Russell crashed an excellent header against the crossbar before Portsmouth debutant Lubomir Michalik headed home substitute Ashley Harris's corner in the second minute of stoppage time, but it was too little too late.