Both sides were reduced to 10 men, with the visitors holding on for 44 minutes with a man disadvantage after Josh Mulligan was shown a straight red card midway through the first half for a late tackle from behind.
The hosts also had a player sent off as David Bangala picked up a second caution just after the hour.
Dundee pounced five minutes later with McCowan slotting into the bottom corner and the same player made sure of the points six minutes from time by finding the net with a 30-yard free-kick.
Ayr dropped into third place as Queen's Park moved up to second with a 4-1 win at struggling Arbroath.
Dom Thomas and Simon Murray struck just before the break and Grant Savoury netted a second-half brace as the Spiders claimed their sixth successive win in all competitions. Daniel Fosu netted a late consolation for the hosts.
Partick Thistle thumped Inverness 5-1 with Brian Graham, Kyle Turner, Cole McKinnon, Aaron Muirhead and Danny Mullen all on the scoresheet. Aaron Doran was on target for the visitors.
Morton battled back from two goals down to draw 2-2 at Raith Rovers. Tom Lang and Aidan Connolly had Raith two up inside 20 minutes but an Andrew McNeil own goal and a Robbie Muirhead finish earned the visitors a point.
Cove Rangers condemned bottom club Hamilton to a fifth straight league defeat with a late double from Leighton McIntosh securing a 2-0 win at Balmoral Stadium.