A Florida social services agency investigated Mr. Cruz after it was alerted about the same disturbing behavior in 2016, but it determined that he was at low risk of harming himself or others. Local sheriffs’ deputies were repeatedly called to Mr. Cruz’s residences but never found reason enough to arrest him. And the F.B.I. failed to investigate tips about Mr. Cruz’s apparent interest in shooting up a school, even after a woman called to say that Mr. Cruz had weapons and was “going to explode.”

At the time when school officials said they would initiate Baker Act commitment proceedings against Mr. Cruz, he apparently did not own any weapon other than a pellet gun. But five months later, after being kicked out of Stoneman Douglas High, he legally purchased the semiautomatic AR-15 rifle that he used to open fire on Feb. 14 in the school’s freshman building.

The mental health records, first reported by The Sun Sentinel of South Florida and The Associated Press, form part of the criminal case against Mr. Cruz, 19, who has been charged with murder and attempted murder in a 34-count indictment. Prosecutors have said they would seek the death penalty if he is convicted.

The records are from Henderson Behavioral Health, a local clinic that school officials called for help dealing with Mr. Cruz. The clinic sent a mobile assistance team to Stoneman Douglas High on Sept. 28, 2016, the records show, because Mr. Cruz had made threats and exhibited disturbing behavior following a breakup with a girlfriend. Mr. Cruz was also said to be upset that his mother, Lynda Cruz, would not let him get an identification card required to buy a gun. He wrote “kill” in a notebook in anger over her refusal, he told a counselor.

Mr. Cruz denied telling another student that he wanted to use a gun or that he had ingested gasoline, the documents say. He also said he would not hurt his mother.