Nearly 30 petrified passengers were trapped on a Midtown hell train yesterday with a knife-wielding madman and the blood-soaked body of a straphanger he just stabbed to death in a senseless argument over a seat.

The Bronx-bound D train came to a screeching halt at around 2 a.m. in the tunnel between the Rockefeller Center and Seventh Avenue stations when a rider yanked the emergency cord after watching the carnage unfold.

WERE YOU ON THE TRAIN? CALL THE NEW YORK POST AT 212-930-8500!

The group of riders were stuck in the car behind locked doors as a pool of blood began to form around the dying man and the suspect, Gerardo Sanchez, 37, of The Bronx, coldly stood over him. Eventually, Sanchez strolled to one end of the car, and the rest of the passengers fled to the opposite end.

Sources identified the victim as Dwight Johnson, 36, who appeared to be homeless.

Sanchez, an exterminator, boarded the train at Rockefeller Center and asked the victim to remove his bag from an unoccupied seat — saying he had just gotten off work and was tired.

Johnson refused, and a cursing match quickly ensued.

The victim, who stood at least 6 inches taller than the 5-foot-6 Sanchez, punched his antagonist in the face, police sources said.

Sanchez — who was still wearing his work shirt emblazoned with his name, “Jerry,” and the company logo, “Terminate Control” — bugged out, pulling a steak knife and plunging it into Johnson’s jugular and hand, police said.

Some of the stunned passengers frantically pounded on the train operator’s door, while another rider pulled the emergency cord.

The train operator radioed the command center, which quickly called police.

“The operator was informed by a passenger that another passenger had been stabbed and that he needed police and medical attention,” said a transit spokesman.

Cops relayed word to the operator to keep the car sealed until they arrived — leaving horrified straphangers trapped in with the killer and the body for about five minutes until the doors opened at the station, the sources said.

Sanchez managed to pry one of the doors open just enough to drop the knife out of the train as they waited for police to arrive, the sources said. Cops later recovered the weapon.

Responding officers found Sanchez standing in front of the train door with several passengers pointing at him, the sources said.

“He punched me in the mouth,” the suspect then allegedly told cops.

Paramedics arrived and declared Johnson dead at the scene.

Police sources said both men had prior arrests — the alleged killer for a 2002 drug case and the victim for weapons possession in 2004.

Sanchez was charged with murder and weapons possession.

His Bronx friends and neighbors were shocked at the violence.

“He was very respectful. He didn’t bother anybody. He was always talking about his son,” said a friend who has known the exterminator since he moved into a Bedford Park rooming house eight months ago.

Robert del Rosario, 20, a bodega worker, was taken aback when he learned the tragic news.

“I still don’t believe it. To me, he was a happy person. He would make jokes in the store and dance to all the songs.

“It must have been in self-defense.”

Additional reporting by Larry Celona