Boro needed a point to reclaim top spot from Leeds United and looked on course for at least that until Ayala's last-gasp intervention to secure a fourth straight win.
The Teessiders had been on top throughout, yet struggled to really test Sam Johnstone, who made only routine stops either side of a glaring Martin Braithwaite miss.
West Brom passed up its own opportunities and the sides were deadlocked until dismal defending from the visitors — uncharacteristic of Pulis's time at the club — cleared a path for Ayala to strike, although it looked as though the goalscorer may have controlled the ball with his hand before firing home.
Home defender Aden Flint almost netted a spectacular own goal to open the scoring early on, thundering Harvey Barnes's right-wing delivery against his own crossbar before Boro took control.
Pulis' side struggled to turn their dominance into an opener, though, and Braithwaite squandered the best chance of the first half as he hacked over from close range.
Dwight Gayle was similarly wasteful when sprinting clear on the break shortly after the restart, the on-loan forward still searching for the clinical form that made him such a match-winner in this division with Newcastle United.
Both teams looked short of ideas in the final half hour, but a foul on Adam Clayton on the left flank allowed Muhamed Besic, making his second Boro debut, to pick out Ayala for his contentious late winner.