The Millers are level on points with second-placed Coventry City, having played a game more, who won 2-1 at Rochdale.
In windy conditions at the Wham Stadium, neither side was able to break the deadlock in the opening 45 minutes.
Rotherham enjoyed a stronger start in the second half and were rewarded with the opening goal when Freddie Ladapo fired home.
But their joy was short lived as Jordan Clark equalised for the hosts almost immediately.
But Wiles made sure all three points returned to Yorkshire as he headed in Dan Barlaser’s cross to make it four wins from the last five games.
Joe Mattock and Matt Olosunde replaced Adam Thompson and Wiles in the starting line-up after the Millers drew 2-2 with AFC Wimbledon in their last outing.
Stanley enjoyed the better of the opening 45 minutes but were unable to make it count.
Ladapo's opener came when he latched onto Michael Ihiekwe's header to fire the ball into the roof of the net.
The Millers were caught napping immediately after, however, as Clark fired a shot into the corner of the net.
But Wiles made sure Rotherham stayed top of the table, coming off the bench to snatch the late winner.