The pilot of a small airplane was lucky to avoid death twice on Sunday — first when he crash-landed onto railroad tracks in Pacoima, then when Los Angeles police yanked him out of the aircraft just seconds before an oncoming commuter train smashed into the plane.

An LAPD officer’s body camera footage captured the dramatic sequence of events, showing police working to free the pilot from the wreckage as an oncoming Metrolink train’s horn blares.

“Go, go, go, go, go!” a man can be heard shouting as the train came heading toward the group.

Right after the officers pull the man clear of the plane, the train can be seen barreling through the aircraft, cutting its fuselage in half.

The incident unfolded shortly after 2 p.m. on the Metrolink Antelope Valley line train tracks near the Whiteman Airport in Pacoima, the LAFD said in a pair of alerts.

The single-engine plane — its tail number of N8056L identifies it as a 1967 Cessna 172H, according to the FlightAware website — had lost power and crash-landed near the intersection of San Fernando Road and Osborne Street, according to the LAPD’s Valley Bureau.

“I saw the plane come down,” said Sgt. Joseph Cavestany, one of the officers who helped rescue the pilot, told reporters during a press conference. “It had looked like he was sideways… I made a request to our communications to stop all rail activity.”

Officer Christopher Aboyte said, upon arriving at the scene of the plane crash, he began speaking with the pilot to try to keep him alert and conscious.

Then came the sound of bells and flashing lights, signaling an oncoming train, the officers recounted during the press conference.

The pilot was the only person on board and was taken to a hospital for treatment, the Los Angeles Fire Department said. He was not identified and no other injuries were reported.

The pilot’s wife told KTLA over the phone on Monday that she’s grateful for the officers who saved her husband’s life.

“Thank you from the bottom of my heart,” she said. “They saved his life…If he had still been in the plane, it would’ve been a horrible event.”