PARKLAND, Fla. — Before he was hauled into a jailhouse hearing room on Thursday, head bowed and shackled at the wrists and ankles, Nikolas Cruz had been causing trouble as long as anyone here could remember.

Neighbors said patrol cars were regularly in his mother’s driveway. More recently, Mr. Cruz, 19, had been expelled from his high school. He posted pictures of weapons and dead animals on social media.

Almost immediately after Mr. Cruz turned up at Marjory Stoneman Douglas High School in Parkland, Fla., Wednesday and, the authorities said, killed 17 people with a semiautomatic rifle, the disconnected shards of a difficult life began to come together. Students and neighbors traded stories of their experiences with him and wondered if anything could have been done.

Some of the stories fell within the bands of typical teenage mischief-making. But others — including a comment on YouTube Mr. Cruz may have posted last year saying he wished to be “a professional school shooter” — were considerably more troubling. The comment, left under the name “nikolas cruz,” was reported to the F.B.I. by someone who did not know Mr. Cruz, and the agency said on Thursday that it had been unable to determine who had posted it.

Mr. Cruz was taken into custody shortly after the massacre, and was booked on 17 counts of premeditated murder. He confessed to the shootings, according to an arrest affidavit. When he appeared via a jailhouse video hookup for his first court appearance on Thursday, the judge asked him whether he understood his circumstances.

“Yes, ma’am,” he whispered.

The authorities released the names of all 17 victims on Thursday. They were teachers and students, the kinds of people who bring a school to life: a popular football coach who himself had gone to the school, a soccer player, a trombonist in the marching band.

Lori Alhadeff, the mother of one of the victims, Alyssa Alhadeff, 14, said she had a message for President Trump.

“President Trump, we need action, we need change,” she said, tears streaming down her face. “Get these guns out of the hands of these young kids and get these guns off the streets.”

The president, who generally opposes new gun restrictions, has focused on mental illness during mass shootings, and did so again on Thursday, beginning with a post on Twitter.

So many signs that the Florida shooter was mentally disturbed, even expelled from school for bad and erratic behavior. Neighbors and classmates knew he was a big problem. Must always report such instances to authorities, again and again!

Pressed repeatedly as to whether he would commit to tightening gun restrictions in his state, Mr. Scott said that he would be “strong on that,” and that “everything is on the table.”

But he also made clear that there were “a lot of things” at play, such as who should have guns, how to make schools safer, and how to make it easier for children to report problems.

Mr. Cruz had no criminal history before the shootings, according to state law enforcement records. But his childhood was certainly troubled.

He spent much of it in a subdivision called Pine Tree Estates, on a lush, narrow street dotted with tropical plants and the occasional driveway basketball hoop. Mr. Cruz and his brother, Zachary, had been adopted, and were raised largely by their mother, Lynda Cruz, especially after their father, Roger P. Cruz, died suddenly in 2004 at the age of 67. Ms. Cruz died in November, and people who knew Nikolas said he had taken the loss hard.

Paul Gold, 45, said he lived next door to the Cruzes in 2009 and 2010 and stayed in touch with Lynda Cruz over the years.

“He had emotional problems and I believe he was diagnosed with autism,” Mr. Gold said of Nikolas Cruz. “He had trouble controlling his temper. He broke things. He would do that sometimes at our house when he lost his temper. But he was always very apologetic afterwards.”

He added: “He would sometimes be hitting his head and covering his ears. One time, I sent him home because he was misbehaving at our house and he took a golf club and smashed one of my trailers.”

He said that Mr. Cruz at one point had gone to a school for students with special needs. “Kids were really picking on him and would gang up on him and beat him up a little,” Mr. Gold said. “They ostracized him. He didn’t have many friends.”

He said that Mr. Cruz’s mother had done what she could to take care of him, and that the two had an extremely strong bond.

“His mother was his entire life and when he lost her, I believe that was it for the boy’s peace of mind,” he said.

Other neighbors said Mr. Cruz was a regular source of agitation. Helen Pasciolla said Lynda Cruz had called sheriff’s deputies to the house numerous times in an effort to keep Mr. Cruz in line. Craig Koblitz, 62, a yacht repairman who lives across the street, said some neighbors had suspected him of burglarizing a nearby house a few years ago.

About six years ago, Mr. Koblitz returned to his home to find Mr. Cruz scooping the fish from the pond in his palm-shaded front yard. He found it odd that the boy did not seem to express much surprise or guilt over being caught stealing.

Video

They Survived the School Shooting. Now They Want Action.

Just hours after 17 people were killed in a mass shooting at their high school in Parkland, Fla., students turned to social media to advocate for more gun control.

Sarah Edelsberg, 16, remembered being frightened by Mr. Cruz when they were in middle school together. Mr. Cruz would walk by her and her friends and shout at them — randomly and menacingly, she said, with wild gestures of his arms.

She said he was small of build, wore a constant smirk and seemed eager to provoke confrontations. Teachers, she said, sometimes dealt with his behavior problems by forcing him to sit outside their portable classrooms.

The authorities said Mr. Cruz was expelled from Stoneman Douglas last year. Victoria Olvera, a 17-year-old junior, told The Associated Press that Mr. Cruz had gotten into a fight with his ex-girlfriend’s new boyfriend.

An error has occurred. Please try again later.

You are already subscribed to this email.

But Michael Goldfarb, whose 17-year-old son Bradley knew Mr. Cruz, said his son had told him Mr. Cruz was expelled for having a knife at school.

Last year, Mr. Goldfarb said, his son went on a three-day trip to a cabin in the Everglades with other young men, including Mr. Cruz. They were accompanied by a parent who owned the cabin.

Shooting weapons was a big part of the trip’s allure. There were two AR-15s on the trip, and Mr. Cruz brought one of them.

He bragged about how he had bought it from a pawnshop, Mr. Goldfarb said, speaking for his son. (The authorities said the gun had been legally purchased from a gun shop.)

The YouTube comment appeared last fall on the channel of Ben Bennight, a bail bondsman in Mississippi.

“I’m going to be a professional school shooter,” the Sept. 24 comment said, under the user name “nikolas cruz.”

Mr. Bennight took a screenshot and flagged it to YouTube, which removed the post. Then, Mr. Bennight said, he left a voice mail message at his local F.B.I. office alerting them about the comment.

Mr. Bennight, 36, said on Thursday that a pair of agents interviewed him the next morning. But the F.B.I. never learned who posted the comment.

“No other information was included in the comment which would indicate a particular time, location, or the true identity of the person who posted the comment,” the F.B.I. said in a statement on Thursday. The F.B.I. said it had conducted database reviews and other checks.

Photo

Students at a prayer service at Parkridge Church in Coral Springs, Fla., to honor the shooting victims.Credit
Saul Martinez for The New York Times

After his expulsion, Mr. Cruz took a job at a dollar store near his old school. Ms. Edelsberg said she had seen him there a number of times. Now, she said, he seemed less scary than friendly. He asked her for news from Stoneman Douglas.

On Thursday, Jordan Jereb, a leader of a white supremacist group based in North Florida, told The Associated Press that Mr. Cruz had joined the group, but later Mr. Jereb said that he did not know whether that was true.

The family of another schoolmate, the Snead family, took in Mr. Cruz because his friend felt badly that Mr. Cruz was now alone in the world, said Jim Lewis, a lawyer for the family. The Sneads had allowed Mr. Cruz to bring his gun with him to their house, insisting that he keep it in a lockbox.

On weekday mornings, Mr. Cruz usually got up to catch a ride to adult education courses that the Sneads had encouraged him to attend. But on Wednesday, he refused to get up, Mr. Lewis said.

Mr. Lewis said Mr. Cruz had said something to the effect of: “I don’t go to school on Valentine’s Day.”

Howard Finkelstein, the chief public defender in Broward County, said in an interview that Mr. Cruz’s legal team had not yet decided whether to mount an insanity defense. Prosecutors have not said whether they will seek the death penalty, but Mr. Finkelstein argued that Mr. Cruz should not be a candidate for execution, given his mental health history.

“Every red flag was there and nobody did anything,” Mr. Finkelstein said. “When we let one of our children fall off grid, when they are screaming for help in every way, do we have the right to kill them when we could have stopped it?”

On Wednesday, Mr. Cruz and the Sneads’ son were texting until 2:18 p.m., Mr. Lewis said — about five minutes before the first 911 calls about the shooting.

“But there was nothing crazy in the texts,” Mr. Lewis said.

Mr. Cruz arrived at the school in a small, gold-colored Uber, according to the booking report from the Broward County Sheriff’s Office. He was wearing a black hat, with a black duffel and a black backpack.

Within a minute there were gunshots.

Later, in custody, Mr. Cruz told investigators that “he was the gunman who entered the school campus armed with an AR-15 and began shooting students that he saw in the hallways and on the school grounds,” the report said.

The police would find him an hour later in the nearby city of Coral Springs. In the report, Mr. Cruz said he had slipped away from the campus by ditching the gun and the extra magazines he brought along, joining the crowd of worried students fleeing the school.

A version of this article appears in print on February 16, 2018, on Page A1 of the New York edition with the headline: Florida Shooting Suspect Displayed Flashes of Rage And Other Warning Signs. Order Reprints|Today's Paper|Subscribe