DETROIT — A 17-year-old student smuggled guns into his school outside a small town north of Detroit, took two hostages and then killed himself, law enforcement officials said. The student, Chris Buschbacher, was despondent about a recent breakup with his girlfriend and legal troubles, officials said. The incident occurred near Caro, a farming town of 4,100 people about 75 miles north of Detroit. The hostages, a 15-year-old female student and a 48-year-old teacher, were released — one in exchange for a pack of cigarettes — before Mr. Buschbacher shot himself with a 20-gauge shotgun. No one else was harmed. Mr. Buschbacher fired only one other shot, into a wall. The Caro schools superintendent, Dennis Anderson, said officials believed that Mr. Buschbacher left the school during a break and then re-entered, with the shotgun and a .22- caliber rifle hidden in a duffel bag, through a rear door that had been propped open. The guns belonged to Mr. Buschbacher, apparently legally, said Undersheriff James Jashinske of Tuscola County. It is legal in Michigan for a 17-year-old to own such weapons, provided the proper safety courses are completed. The school, the Adult Learning Center, is an alternative school for students "who for one reason or another are having trouble," Mr. Anderson said. Lt. James Giroux of the Tuscola County Sheriff's Department, who talked to Mr. Buschbacher during most of the standoff, said Mr. Buschbacher had told him he was despondent. "He was generally upset about the condition of his life, just everything," Lieutenant Giroux said. Neither of the hostages was specifically targeted by Mr. Buschbacher, the lieutenant said. The girl was freed about an hour into the negotiations when Lieutenant Giroux agreed to give Mr. Buschbacher a pack of Marlboro cigarettes and a lighter. About an hour and a half later, the teacher, Joseph Gottler, was released. Neither metal detectors nor security cameras are used at any of the Caro schools, Mr. Anderson said, adding that now officials "will take a look at everything."