Broward County Public Schools disciplinary records obtained on Saturday by The New York Times show Mr. Cruz had a long history of fights with teachers, and was frequently accused of using profane language with school staff. He was referred for a “threat assessment” in January 2017, the last entry in his record, two months after the Department of Children and Families closed its separate investigation into Mr. Cruz’s worrisome behavior.

Howard Finkelstein, the Broward County public defender, whose office is representing Mr. Cruz, said the report was further evidence that Mr. Cruz needed serious help long before the shooting but did not get enough of it.

“This kid exhibited every single known red flag, from killing animals to having a cache of weapons to disruptive behavior to saying he wanted to be a school shooter,” Mr. Finkelstein said. “If this isn’t a person who should have gotten someone’s attention, I don’t know who is. This was a multisystem failure.”

The state agency investigated whether Mr. Cruz intended to harm himself in September 2016, when he made the alarming social media posts after an argument with his mother. Mr. Cruz, who had depression, was upset over a breakup with a girlfriend, his mother, Lynda Cruz, told investigators. The report does not say who called in the complaint, which was given “immediate” priority.

The report shows that investigators closed the case about two months later. The agency determined that the “final level of risk is low” — an analysis that one of Mr. Cruz’s counselors at his school felt was premature — because his mother was caring for him, he was enrolled in school and he was receiving counseling. By the time of the shooting, however, Mr. Cruz had lost at least two of those elements: His mother was dead, and he had left Stoneman Douglas High School. It is unclear if he was still seeing a counselor.