SANTA FE, Tex. — In many ways, Santa Fe High School followed the playbook for how to confront a school shooting.

When gunfire erupted on Friday morning, two police officers stationed at the school confronted the gunman within about four minutes, law enforcement officials reported Monday, offering new details on how the police brought the shooting spree to an end. The Galveston County Sheriff, Henry Trochesset, said the officers hemmed the gunman into one classroom and saved lives by drawing his attention and fire.

Even before then, the students and teachers at Santa Fe High had prepared for how to respond to a shooting: Through regular active shooter drills, they knew to barricade themselves in classrooms and flee the school grounds quickly and fluidly. Other police officers among the more than 200 who eventually responded had done “alert training” and kept their marksmanship honed.

All of this, and still 10 people were killed and 13 wounded.

That a 17-year-old armed with his father’s revolver and shotgun could exact such a toll despite what officials here have called a swift, aggressive response further underlined the limits of training, preparation and readiness.

“Luckily, the body count’s not higher,” Sheriff Trochesset said at a news conference on Monday.

The sheriff told reporters that the two officers — one of whom was critically wounded by the gunman — had kept the suspect, identified as Dimitrios Pagourtzis, “contained and engaged” as scores of officers from across the area rushed to the school to evacuate students and educators.

“It was contained in that one area, which saved so many lives,” he said. “And again, I’m going to take it personal: three doors down, my granddaughter was in that room. I think they’re heroes, everybody that was out there that stayed engaged with him.”

Sheriff Trochesset said the gunman tried to shoot at the police, and that officers fired “minimal” shots during a standoff before the suspect surrendered. Mr. Pagourtzis faces multiple murder charges and is now being held in the county jail under suicide watch, the sheriff said.

The sheriff said he did not believe that any of the 10 people who were killed were shot by law enforcement officers, but he said he could not definitively confirm that until after autopsies were performed. He declined to say how many officers fired their weapons.

“Again, this is a fluid investigation that is still ongoing,” he said.

The officers’ rush to confront the gunman offered a sharp contrast to how a Florida sheriff’s deputy responded to gunshots at Marjory Stoneman Douglas High School in Parkland, Fla., in a Feb. 14 attack that left 17 people dead. The former Broward County deputy, Scot Peterson, was criticized for taking cover behind a wall and not heading inside to confront the gunman during the deadly six-minute rampage.

Sheriff Trochesset had special praise for Officer John Barnes, one of the two officers who first confronted the gunman. Officer Barnes was gravely wounded by a shotgun blast to the right arm, and remained in critical condition on Monday, the sheriff said.

“Officer Barnes is a hero,” the sheriff said. “The two officers that engaged that individual within four minutes, or approximately four minutes — they’re heroes. They contained him in that one area, isolated to them and engaging with them, so he did no more damage to other classes.”

Officer Barnes’s gun was out and his arm was extended, family members said, but it was not clear whether he had fired.

As he lay bleeding on the floor of the school, Officer Barnes urged the other officer to leave him behind and see to the students, according to his stepfather, Ronald Hatchett. The other officer later returned and tied a tourniquet around Officer Barnes’s arm.

“It was entirely within his character to do what he did,” Mr. Hatchett said of his stepson in an interview on Sunday. “He was first through the door. He suffered for being first through the door.”

Image Officer John Barnes, who was wounded in the shooting at Santa Fe High School. Credit... via Houston Police Department

Of the 13 people wounded in the deadly shooting on Friday, Officer Barnes, 49, may now face the hardest, most tenuous path.

The police chief of the Santa Fe school district, Walter Braun, told reporters on Monday that Officer Barnes remains in intensive care at the University of Texas Medical Branch in Galveston, recovering from surgeries. “He’s had ups and downs,” Chief Braun said. “Today was a down day, so we’re still in prayer and hope that he can recover.”

Officer Barnes lost huge amounts of blood after the shotgun blast shredded his right elbow. His heart stopped twice, Mr. Hatchett said — once while he was being evacuated by helicopter to the hospital, and again on the operating table. His kidney function was still “in peril,” and doctors do not yet know how his arm will be affected, Mr. Hatchett said.

“He is by no means completely out of the woods,” he said.

For a while on Saturday, the doctors eased back on the sedation, allowing Officer Barnes to open his eyes from his hospital bed, hold his wife’s hand and listen to his family tell him that they loved him.

“Everybody said, ‘You’re a real hero, John — we’re so proud of what you’ve been doing,’” Mr. Hatchett said. “We told him we’re going to be here with you.”

Since he was 10, John Barnes had wanted to be a cop, Mr. Hatchett said. In old photos that the family has been flipping through lately, he can be seen holding a BB gun with a law enforcement officer’s posture and authority.

His mother worried about what could happen to him and tried to dissuade him from a police career, Mr. Hatchett said, “but he never wavered.”

He worked as a corrections officer in Tarrant County, which includes Fort Worth, until a spot opened up at the police academy in Houston in 1994. He struck other cadets there as friendly and engaging, introducing himself so often as “John Barnes from Tarrant County” that they nicknamed him Tarrant County.

He was interested in the intricacies of police work and asked instructors question after question, to the point that his questions ate into the cadets’ break time, according to a friend, Capt. Jim Dale of the Houston Police Department.

Among his assignments on the Houston force were investigations of sex crimes, and he once pulled a man from a burning car, family and friends said. He retired from the force in January and began working in the Santa Fe schools, where his wife, Ashley, is an assistant principal at Roy J. Wollam Elementary.

He told Captain Dale he was seeking a “simpler life,” one in which he would work closer to home and have summers free with his wife, 10-year-old daughter and 15-year-old son.

Even so, his stepfather said, Officer Barnes recognized the stress and complexities of working in a school of 1,400 students, and had trained with other officers for the possibility of a school shooting.

The force that covers the Santa Fe schools has seven officers — including a chief and assistant chief — as well as a dispatcher and auxiliary officers, according to its website. The school district’s police chief did not return a phone message seeking comment.

“They had an anti-shooter plan that they’d been working on,” Mr. Hatchett said. “John had extensive practice at the firing range to make sure his skills were up to snuff.”

His family now takes turns staying beside Officer Barnes’s bed — all except his wife, who has been there constantly since she heard the news that a Santa Fe school officer had been shot. Amid phone calls and plaudits from the governor, other political figures and higher-ups in law enforcement, Ms. Barnes told her husband’s friend, Captain Dale, that she did not see what the big deal was about what he had done on Friday.

“John’s a hero all the time,” she told him.