A man has died after he was shot by an off-duty police officer after trying to rob a gas station in Brooklyn on Monday night, the NYPD said.

It happened on Remsen Ave. near Avenue D in Canarsie around 10:35 p.m.

The offer was in his private car as a station attendant pumped gas for him, when two men approached them, armed with guns, according to the NYPD.

Police said one man entered the station attendant's booth and demanded money from a second employee, as the second armed man remained outside and told the off-duty officer and the gas station attendant not to move.

As the two armed men left the gas station, the off-duty officer identified himself as a police officer and told them to stop.

After the men turned towards the officer with their guns in their hands, according to officials, the officer shot one of them in the torso. The second man fled the scene for Avenue D.

The man who was shot was transported to a local hospital and was pronounced dead 12:13 a.m. Tuesday, authorities said.

The off-duty officer was not injured, but he was taken to a local hospital for ringing in his ears.

Police said a firearm from one of the robbers was recovered.

An investigation is ongoing.

The armed man who fled the scene is described as 6 feet tall, last seen wearing a grey-hooded sweatshirt, and blue jeans.

Anyone with information on the case should contact the Crime Stoppers hotline at 1-800-577-8477, or text CRIMES and then enter TIP577, or visit www.nypdcrimestoppers.com