The crazed gunman who wounded four Brooklyn cops was reaching for another rifle loaded with more powerful, armor-piercing bullets to inflict deadly injuries just before he was stopped, officials said yesterday.

“If he would have been able to grab that gun, this would have been a lot more tragic. It would have been in God’s hands,” said a police official familiar with the case.

“It’s apparent [the suspect] wanted to shoot it out with cops and go out in a blaze of glory.’’

Cops said the ammo from suspect Nakwon Foxworth’s sawed-off military assault weapon would have easily pierced the Kevlar shield that hero Detective Kenneth Ayala used to protect his comrades and himself from the perp’s initial 12-bullet barrage from a 9mm revolver.

The more powerful bullets also would have gone through the officers’ vests, police said.

Ayala, 49 — who took bullets to his thigh and ankle even as he shielded his comrades and fired back — yesterday was released from Lutheran Medical Center, to the applause of 50 cops from his elite Emergency Service Unit.

“It’s good to go home,” the married dad said as he was wheeled out.

Despite his bravery and high praise from colleagues, Ayala refused to be hailed as a hero.

“We all work together,” he said.

When the cop reached his Brooklyn home and hobbled inside on crutches, an NYPD bagpiper saluted him.

The bloodshed began when Foxworth returned home with his pregnant girlfriend and 4-month-old son after a party late Saturday. He became enraged when he couldn’t get his daughter’s stroller through a door to the apartment building because of movers’ equipment, residents said.

He started waving a gun, and one of the movers called 911. Foxworth then barricaded himself in his sixth-floor apartment with his girlfriend and the baby.

Moments after the ESU team arrived, the terrified girlfriend ran out of the apartment, with the child, to safety. She later told cops that, moments earlier, Foxworth had started loading all three of his illegal weapons.

As the cops entered the apartment, Foxworth started shooting, police said. In addition to wounding Ayala, the perp shot cop Michael Keenan in his left calf. Keenan remained hospitalized last night.

Officer Matthew Granahan, 35, also was hit in the left calf, and Capt. Al Pizzano, 45, suffered a graze wound to the face. Both were treated and released Sunday.

Fortunately for them all, Foxworth, 33, only managed to fire his semiautomatic before being badly wounded by return fire, authorities said.

He stumbled into his bedroom to try to retrieve the assault rifle but never got to it, they said.

He was shot by cops once through the stomach, with the bullet exiting his buttocks. He remains hospitalized in critical but stable condition.

Additional reporting by Jennifer Bain, Antonio Antenucci, Franz Koster, Ikimulisa Livingston, David Seifman and Natasha Velez