The 17-year-old suspect entered Patongprathankiriwat School in Songkhla Province's Hat Yai earlier in the day, appearing agitated, the provincial government said in a statement.
The suspect has a sister at the school, police commander Teerasak Chaiyotha said, but a motive has yet to be determined.
A female teacher was critically injured and had undergone surgery and was now in an intensive care unit while a teen girl was shot in the waist and was in a stable condition, he added.
In a photograph shared by police, the suspect, barefoot and wearing shorts and a T-shirt, is shown pinned to the ground by armed officers.
He had earlier attacked a police officer and stolen his firearm, provincial governor Ratthasart Chidchoo said, adding that the suspect had a history of substance abuse and was discharged from a psychiatric hospital in December.
In a video obtained by Reuters, armed police officers storm the three-storey school building as gunfire rings out.
Another video shows students running down staircases while police - some wearing helmets, black bulletproof vests and carrying rifles - shout: "Go home kids, it's safe."