The game was marred by an injury to Pim Balkestein when the game was held up for eight minutes near the end.
Swindon started well and deservedly took the lead after eight minutes when a superb 40-yard pass put Danny Ward clear on the left and Billy Paynter finished clinically from his cross.
The Robins continued to press but they let Brentford back into the game in the 33rd minute when David Hunt shot home from just inside the area after the home defence failed to clear.
Swindon were showing signs of nerves but they were calmed to some extent on the stroke of half-time when Jon-Paul McGovern did well to provide a cross which travelled through a crowded penalty area, and the unmarked Ward calmly shot past Wojciech Szczesny for a deserved interval lead.
Paynter added to his tally in the 58th minute with a header from Frank Nouble’s cross but Ben Strevens immediately pulled a goal back for the visitors. But Swindon hung on to set up a thriller against promotion rivals Millwall next week.