Kevin O'Hara scored the only goal of the game after 18 minutes as Peter Grant's team upset the odds against Robbie Neilson's men.
The result also means that Ayr United will go top if they avoid defeat against Inverness Caledonian Thistle at Somerset Park this afternoon.