The Welsh side took the lead midway through the first half with a goal from Michael Bakare but the Staggies turned the game round in the closing stages.
Josh Mullin equalised with 15 minutes left and the former Livingston winger scored again soon after. Jamie Lindsay sealed the win for Steven Ferguson and Stuart Kettlewell's men with four minutes remaining.