Newly released footage shows the tense moments before a gun battle between police and the Elizabeth man who planted two bombs in New Jersey and New York that injured 30 people.

Three days after the September 2016 bombings, Ahmad Khan Rahimi, 31, was arrested after being shot multiple times in a gun battle with police on a Linden street. Two officers – Anthony Padilla and Pete Hammer Jr. – were both injured in the shootout. Both officers survived.

The bodycam footage, first obtained by WNBC New York, shows an officer's exchange with Rahimi immediately preceding the shootout that ended in Rahimi's arrest. In the footage, Padilla approaches Rahimi, who was huddled in the covered vestibule of a bar. Less than two minutes later, two gunshots are heard as Padilla retreats to his car to chase after the fleeing Rahami, the footage shows.

"Shots fired," Padilla says in the footage. "He hit me in the vest. He's shooting at the cars."

The footage is the latest key piece of evidence in an ongoing trial for charges that include attempted murder directly linked to Rahimi's arrest after a three-day spree of bombings.

In October 2017, Rahimi was found guilty of planting two pressure-cooker bombs, including one that injured 30 people on 23rd Street, in the Chelsea neighborhood, during the September 17, 2016 attack.

Two days prior, Rahimi, who was born in Afghanistan, planted a pipe bomb along the route of a Marine Corps charity race in Seaside Park. The bomb detonated, but no one was injured in the explosion because the race had been delayed. The race was then canceled.

The morning of the shootout, bombs were also discovered in a trash can near the Elizabeth train station. Police accidentally detonated one of the bombs with a robot as they were attempting to recover them.

Rahimi was sentenced to multiple life terms for the New York City attack.

Now, Rahimi faces a charge of attempted murder for the shootout. The footage depicts Padilla's encounter with Rahimi mere minutes before gunshots rang out in Linden.

NJ COMMUTE:Port Authority approves toll hikes; steepest rate increases coming to commuters

FOR SUBSCRIBERS:Hundreds of thousands of students exposed to lead in NJ schools. Here's why officials failed to stop it

After Padilla asks Rahimi why he was sitting in the bar entrance, Rahimi tells Padilla he has no identification and is homeless, according to the footage. When Padilla asks if Rahimi has anything in his pockets he shouldn't have, the exchange quickly escalates as Padilla shouts repeatedly for Rahimi to take his hand away from the inside of his jacket, the footage shows.

"Take your hand away from it right now! Take your hand away from it!" Padilla yells in the footage, before two gunshots are fired.

After returning to his patrol car, Padilla is heard telling dispatch that Rahimi had taken off with a handgun. Padilla was struck in the abdomen, but a protective vest stopped the bullet.

Hammer was injured when a bullet shattered the windshield of his car, blowing glass shrapnel into his forehead, said Pete Hammer, his father.

Rodrigo Torrejon is a breaking news reporter for NorthJersey.com. For unlimited access to all the major news happening in North Jersey, subscribe here. To get breaking news directly to your inbox, sign up for our newsletter.

Email: torrejon@northjersey.com Twitter: @rodrigotorrejon