The suspect, 17-year-old Dimitrios Pagourtzis, has been charged with capital murder, Galveston County Sheriff Henry Trochesset said.
He had posted a picture of himself on Facebook wearing a “Born to Kill” shirt, authorities said.
Texas governor Greg Abbott said he used a shotgun and .38 revolver, obtained from his father, in the attack at Santa Fe High School.
Though both guns were legally owned, it is not clear whether the suspect’s father knew his son had taken them.
Mr Abbott said the suspect had “information contained in journals on his computer … in his cellphone that said not only did he want to commit the shooting, but he wanted to commit suicide after the shooting”.
But Pagourtzis gave himself up, and did not “have the courage” to take his own life, Mr Abbott said.
Explosive devices including a molotov cocktail were found in the suspect’s home and a vehicle, Governor Abbott added, as well as around the school and nearby.
“One or two” other people were being interviewed.
A police officer was among those injured.
A Texas hospital said it had treated eight patients. Dr Safi Madain, from Clear Lake Regional Medical Centre, said six of them had since been discharged.
One was in a critical condition, and another in a stable condition.
All appeared to be high school students with gunshot wounds, the doctor said.
We grieve for the terrible loss of life, and send our support and love to everyone affected by this horrible attack in Texas. To the students, families, teachers and personnel at Santa Fe High School – we are with you in this tragic hour, and we will be with you forever… pic.twitter.com/LtJ0D29Hsv
— Donald J. Trump (@realDonaldTrump) May 18, 2018
Student Courtney Marshall, 15, said the gunman came into her art class. She saw at least one person hit.
“I wanted to take care of my friends, but I knew I had to get out of there,” she said.
“I knew the guy behind me was dead.”
Another student, 18-year-old Logan Roberds, said he heard a fire alarm and went outside.
He then heard two loud bangs, which he did not initially think were gunshots.
Later, he heard three loud bangs. “That’s when the teachers told us to run,” he said.
He went with other students to a nearby petrol station.
Tristen Patterson, 16, said he considered Dimitrios Pagourtzis to be a friend, adding that Pagourtzis was interested in guns and war simulation video games.
Pagourtzis would sometimes enter the classroom “acting a little bit down or sad, a little bit sluggish”, Patterson said. “But he never talked about why.”
Father Stelios Sitaras of Assumption of the Virgin Mary Greek Orthodox Church in Galveston, Texas, said he met Pagourtzis when the teenager danced at an annual festival in October.
The priest said he had never heard of the young man being in trouble.
More from United States
Mother scares off black bear attacking daughter, five, in Colorado
Gaza counts its dead as embassy opens
‘Here we go again’: Hero pilot says doomed flight reminded her of navy career
US to help N Korea’s economy if it abandons nuclear weapons
Donald Trump hails Kim Jong Un as North Korea prisoners arrive home
Hero Southwest pilot Tammie Jo Shults describes ‘flashback’ moment during crash
“He is a quiet boy,” he said. “You would never think he would do anything like this.”
President Trump tweeted: “We grieve for the terrible loss of life, and send our support and love to everyone affected by this horrible attack in Texas.”