The Staggies' nine-point lead over second-placed Dundee United, who only have three games remaining, and huge goal-difference advantage means they are now highly unlikely to be usurped from top spot.
Graham missed an early chance from a corner before play-off hopefuls Ayr took the lead in the 11th minute, Calvin Miller scoring at the back post from a Nicky Cadden cross.
Ross Doohan tipped a Graham header over the bar as the Staggies fought back and, four minutes before the break, the latter smashed home from nine yards by connecting with a fine pass from Josh Mullin.
Imposing frontman Graham picked up where he left off as soon as the second half began, his header from close range giving Ross County the lead.
In the 71st minute the ex-Dundee United striker completed his treble, also boosting the Staggies 20 clear of his former club in the goal-difference column, after Michael Gardyne whipped in a cross.