It was a Monday afternoon and a 30-year-old man was ranting on an F train headed through Manhattan. He was a regular on the subway, once a gifted Michael Jackson impersonator, but he was also troubled. City workers had tried to help him for years.

Inside the same car was a 24-year-old Marine veteran. After the military, he had dropped out of college, posting online about feeling “completely unfulfilled,” and now he was looking for a bartending job in the city.

The man behaving erratically, Jordan Neely, was homeless. He shouted to others on the train that he was hungry, that he didn’t care about returning to jail, that he was ready to die, witnesses said.

What exactly happened over the next several minutes is unclear, but eventually the veteran, Daniel J. Penny, placed Mr. Neely in a chokehold — one similar to what he would have been taught in basic training, but with a crucial difference — and took him to the floor in a minutes-long struggle that ended Mr. Neely’s life and stirred outrage throughout the city.

Their encounter, captured on video by another passenger, has once again revealed the deep fault lines in the ways New Yorkers, and Americans beyond, view race, homelessness, crime and how some people seem to be treated differently by the police. The veteran, Mr. Penny, who is white, was questioned by the police, but has not been charged with a crime for killing Mr. Neely, who was Black.

Was this a citizen trying to stop someone from hurting others? Or an overreaction to a common New York encounter with a person with mental illness?

As investigators examine the moments before Mr. Neely’s death, friends and family told of the slain man’s sunny and upbeat demeanor as he struggled after his mother’s murder when he was a teenager. More recently, he seemed in the grip of serious mental illness and had occasional outbursts of violence.

Less is known of Mr. Penny, who spent most of the last several years outside New York.

On Friday, Mr. Penny’s lawyers, Steven M. Raiser and Thomas A. Kenniff, released a statement. “When Mr. Neely began aggressively threatening Daniel Penny and the other passengers, Daniel, with the help of others, acted to protect themselves, until help arrived,” it read. “Daniel never intended to harm Mr. Neely and could not have foreseen his untimely death.”

Mr. Neely’s childhood was abruptly derailed when he was 14. He lived with his mother, Christie Neely, and her boyfriend in an apartment in Bayonne, N.J. (Reached earlier this week, his father declined to comment.)

In 2007, Ms. Neely disappeared. Her body was found stuffed in a suitcase in the Bronx.

She had been strangled; her boyfriend was charged with murder.

“The relationship had been crazy,” Mr. Neely testified at the boyfriend’s trial when he was 19. “A fight every day.”

Mr. Neely attended Washington Irving High School in Manhattan, where classmates were aware of his loss. Perhaps to deflect from talking about the painful experience, he leaned into his childhood love of Michael Jackson, which by then had grown into a fine imitation.

“Everyone called him Michael Jackson,” said Wilson Leon, 30, a classmate. “The Michael Jackson of Washington Irving.”

“He would be very passionate about dancing,” Mr. Leon said, “very good behavior with the teachers.”

But Mr. Neely dropped out, his family said this week. In later years, he turned up on social media, executing highly choreographed Jackson impersonations in the subways, dressed like the performer in his prime.

Mr. Leon happened upon his old friend’s performances — “sometimes 42nd Street, sometimes the L train,” he said. “We would say hi to each other.”

But Mr. Neely had others watching him, concerned for his safety.

He was well known for years to the social work teams that reach out to homeless people on the subways, and had hundreds of encounters with them, according to an employee of the Bowery Residents’ Committee, a nonprofit organization that does subway outreach for the city.

Mr. Neely was on what outreach workers refer to as the “Top 50” list — a roster maintained by the city of the homeless people living on the street whom officials consider most urgently in need of assistance and treatment. He was taken to hospitals numerous times, both voluntarily and involuntarily, said the employee, who spoke anonymously because they were not authorized to discuss his history.

Mr. Neely racked up more than three dozen arrests. Many were of the sort that people living on the street often accrue while homeless, like turnstile-jumping or trespassing. But at least four were on charges of punching people, two of them in the subway system.

Outreach workers noted that Mr. Neely heavily used K2, the powerful, unpredictable synthetic marijuana. In June 2019, an outreach worker noticed that Mr. Neely had lost considerable weight and was sleeping upright. Around that time, he was reported to have banged on a booth agent’s door and threatened to kill her, according to the worker’s notes. Then he was gone.

In November 2021, Mr. Neely’s aggression seemed to peak, when he punched a 67-year-old woman in the street on the Lower East Side, breaking her nose, the police said. He was charged with assault and, awaiting the resolution of his case, spent 15 months in jail, the police said, though his family said the stint was shorter.

He pleaded guilty on Feb. 9 of this year, in a carefully planned strategy between the city and his lawyers to allow him to get treatment and stay out of prison. Even the victim signed off on the plan.

“Do you know what the goal is today?” the judge, Ellen M. Biben, asked at the hearing.

“Yes,” Mr. Neely replied.

“What is that goal?”

“To make it physically and mentally to the program.”

He was to go from court to live at a treatment facility in the Bronx, and stay clean for 15 months. In return, his felony conviction would be reduced. He promised to take his medication and to avoid drugs, and not to leave the facility without permission.

“This is a wonderful opportunity to turn things around, and we’re glad to give it to you,” Mary Weisgerber, a prosecutor, said.

“Thank you so much,” Mr. Neely replied.

But just 13 days later, he abandoned the facility. Judge Biben issued a warrant for his arrest.

In March, an outreach worker saw him in the subway, neatly dressed, calm and subdued, and got him a ride to a shelter in the Bronx. (The outreach workers typically do not check for arrest warrants when interacting with homeless people.) But a downward spiral followed.

On April 9, when outreach workers approached him in a subway car at the end of the line in Coney Island, Mr. Neely urinated in front of them. When an outreach worker went to call the police, according to a worker’s notes, Mr. Neely shouted, “Just wait until they get here, I got something for you, just wait and see.”

Officers arrived and ejected Mr. Neely from the train, apparently unaware of the arrest warrant.

Five days after that, an outreach worker saw him in Coney Island and noted that he was aggressive and incoherent. “He could be a harm to others or himself if left untreated,” the worker wrote.

Two weeks later, he was riding an F train in SoHo for what would be the last time.

Less is known about Mr. Penny, six years out of high school, four of them spent in the Marines. He received several ribbons and awards common in peacetime activity, according to his military records, and was promoted to sergeant before leaving active duty in 2021.

A person named Danny Penny with an identical military background posted on Harri.com, a website for those seeking work in the hospitality industry, that he had tried college, “felt completely unfulfilled” and “decided to drop out of school and backpack throughout Central America.”

He worked for several months, until last May, at a surf shop in North Carolina near the Marine base where he was last stationed, Camp Lejeune.

“He loves anything surfing related,” said Sam Santaniello, 19, who worked at the shop with Mr. Penny. “He’s a people person. He’s a very easygoing person. Not a lot stresses him out.”

Mr. Penny posted on the hospitality site that he dreamed of bartending in Manhattan.

“During the travels I rediscovered my love for interacting and connecting with people,” he wrote. “Being able to serve and connect with the most interesting and eccentric the world has to offer, is what I believe I am meant to do.”

More details will emerge describing the moments leading up to the chokehold on the train. But one thing seems clear: The maneuver resembled one Mr. Penny almost certainly was taught in the Marines.

“These choking techniques, if applied properly, are a fast and safe way to knock out the enemy,” a sergeant said in an article on the Marines website.

New Marines are trained to apply a “blood choke,” which, when done properly, cuts off blood and oxygen to the brain in as little as eight seconds. But it is imperative in a blood choke to not squeeze the person’s windpipe, which could lead to injury or worse, according to training documents.

On the F train on May 1, Juan Alberto Vazquez, a freelance journalist, began recording video after Mr. Penny had placed Mr. Neely in a headlock. He said later that Mr. Neely had been yelling about being hungry and unafraid to die, but it is unclear if he had physically threatened anyone. It is also unclear whether Mr. Neely and Mr. Penny interacted before the encounter, but Mr. Penny and the other riders on the train would not have known about Mr. Neely’s history of arrests.

Mr. Penny held Mr. Neely down. The restrained man thrashed and kicked for at least two minutes before becoming limp. Two men hovered over the action, helping to pin down Mr. Neely.

“You don’t have to catch a murder charge,” another passenger can be heard saying on the video. “You got a hell of a chokehold, man.”

It is unknown whether Mr. Penny was attempting the blood choke he had learned a few years earlier. The moment when Mr. Neely should have lost consciousness — after eight seconds or so — had long passed.

One witness, Johnny Grima, said he entered the subway car while Mr. Penny was still choking Mr. Neely but after Mr. Neely had stopped moving. “When they let him go, Jordan’s eyes were open, staring out into space and he was limp,” said Mr. Grima, 38, a formerly homeless man who lives in the Bronx and did not know Mr. Neely.

In the video, as Mr. Penny lets go and stands up, Mr. Grima can be heard saying, “Don’t leave him on his back, though, man, he might choke on his own spit if you put him on his back — put him on his side.”

One of the men who had been holding Mr. Neely down complies with the request, rolling Mr. Neely onto his side. While he does so, Mr. Penny fetches a baseball cap from under a subway seat, which he had apparently dropped in the struggle, and puts it back on.

Six hundred miles away, Mr. Penny’s surfing friend, Mr. Santaniello, watched the video like countless others. He could only guess at Mr. Penny’s mind-set: “Knowing Danny and knowing his intentions, it was to help others around him.”

Subway riders and transit workers called for help. Paramedics took Mr. Neely to a hospital, where he was pronounced dead.

Jonah E. Bromwich, Maria Cramer Chelsia Rose Marcius, Hurubie Meko and Dave Philipps contributed reporting.