The man had been in a confrontation on a train just before when he walked off and ran along the tracks, police said.

He then lay down in front of an oncoming train after a brief conversation with Ortiz, refusing to budge.

New Jersey Transit officer Victor Ortiz struggled with the man lying on the tracks before his heroic rescue. (New Jersey 101.5 via YouTube)

Security footage showed Ortiz dragging the suicidal man off the tracks as he struggled to stay put for the train.

Ortiz manages to overpower the man at the last second, saving his life.

Witnesses at the train station were yelling "you're a hero" to Ortiz, the NJ Transit police union said.

Victor Ortiz had been an oficer with the NJ Transit police department for 16 years. (NJ Transit Police Department)

"Without regard for his own safety, Officer Ortiz acted quickly and heroically and was able to pull a man from the train tracks just seconds before a train passed through," the union said in a statement. "We commend Officer Ortiz for his bravery and heroism."

At a few moments during the life-or-death tug of war, the unidentified man had almost pulled Ortiz onto the tracks.

The officer had been on the department for 16 years prior to his heroic action.

"NJ Transit could not be more proud of Victor Ortiz and of the New Jersey Transit Police Department and we hope this serves as a stark reminder of what these men and women do ever single day to keep us safe throughout this state," the agency said in a statement.