NEW YORK - Two NYPD officers from Long Island were among four officers shot on Saturday night after they responded to a man with a gun at a Brooklyn apartment building.

Capt. Al Pizzano, of Smithtown, and officer Matthew Granahan, of Nesconset, were released from Lutheran Medical Center in Brooklyn. Pizzano was hit in the face, and Granahan was hit in the leg.

Kenneth Ayala, 49, and 52-year-old Michael Keenan, are still hospitalized in stable condition, according to the NYPD.

The alleged gunman, Nakwon Foxworth, barricaded his pregnant girlfriend and their 4-month-old son in his apartment, officials say. He has since been formally charged with a number of charges, including attempted murder and assault on a police officer.

After the girlfriend fled the scene with the child, police officers entered the apartment, where they were immediately fired upon.

Although hit, Ayala and Granahan returned fire, striking Foxworth in the abdomen.