Heracles had not lost in four matches to move two points ahead of Feyenoord in the battle for European qualification behind the title challengers PSV Eindhoven and Ajax, who both play later this weekend.
However, John Stegeman's men were behind after only four minutes when Vincent Janssen capitalised on a poor defensive header to put AZ into an early lead at Polman Stadion, as the visitors chased a sixth straight league win of 2016.
A penalty from Markus Henriksen made it 2-0 after 32 minutes, with another from Joris van Overeem just two minutes later stunning the home support.
Thomas Bruns (39) pulled one back before half-time with a fine 20-yard strike, but Alireza Jahanbakhsh (64) restored AZ's cushion.
Mark-Jan Fledderus (67) and then Wout Weghorst (74) on the break reduced the deficit to 4-3.
However, hopes of a dramatic finale were ended with 10 minutes left when Bruns flicked a near-post corner into his own net.
A close-range header from Ben Rienstra completed the scoring in the 84th minute as AZ moved fourth, a point ahead of Feyenoord who travel to PEC Zwolle looking to end their six-match losing streak.
Twente continued their climb away from the relegation zone with a 1-0 win at Roda JC.
Chinedu Ede's goal after 62 minutes proved enough to secure a third straight victory for Renee Hake's side.
Vitesse won for the first time in five league matches as they beat Heerenveen 3-0 at GelreDome.
Denys Oliynyk set the home side on their way when he tapped in at the far post after 20 minutes, with Valeri Qazaishvili adding a second just before half-time.
Qazaishvili made it 3-0 from the penalty spot after 53 minutes.
The day's other match saw relegation-battlers De Graafschap earn a goalless draw at Willem II.
The point moves De Graafschap off the foot of the table above Cambuur on goal difference, while for Willem II it was a third straight 0-0 draw.