By Erin McClam and Alastair Jamieson, NBC News

With a sawed-off shotgun pointed straight at him, a New Mexico social studies teacher calmly talked a 12-year-old student into putting down his weapon — and stopped the country's latest school shooting from being something much worse.

Two students were shot, an 11-year-old boy hit in the face and a 13-year-old girl hit in the shoulder. The teacher, John Masterson, was being praised as a hero for ending the crisis Tuesday before others were shot.

"He is an amazing man," said Gov. Susana Martinez, who met with the teacher. "He stood there and allowed the gun to be pointed right at him so there would be no more young kids hurt."

The suspected shooter, whose name has not been released, was in police custody early Wednesday. State police said the boy came to Berrendo Middle School on Tuesday morning with a 20-gauge, sawed-off shotgun hidden in a bag.

Authorities said he opened fire just after 8 a.m. in the gym, where about 500 students had gathered before class.

"I just saw blood everywhere," Essance Sosa, 12, told The Associated Press. "Everyone started screaming and running."

The two victims taken to a local hospital, then flown by helicopter to a better-equipped facility in Lubbock, Texas. The boy was taken to surgery twice and was listed in critical coundition. The girl was stable.

The boy's name was not released. The girl was identified by the governor as Kendal Sanders.

"I am asking that all New Mexicans keep these children in your prayers," Martinez told reporters.

According to an account given by the governor, Masterson, the teacher, was facing away from the shooter, and the shooter away from him, when the first shot was fired. The teacher thought it was a firecracker, she said.

The teacher wheeled around and saw the young man fire more shots before pointing the gun at Masterson, she said. The teacher talked to him and urged him to put the gun down.

The shooter put the gun down and raised his hands, and the teacher put him up against a wall, the governor said. Just then, an off-duty police officer arrived — he was dropping his own son off at the school — and they contained the student.

The teacher and the off-duty officer, Lt. Gary Smith, drew praise from authorities for their bravery.

"It's one thing for an armed state police officer to enter a school and do his or her job," said Pete Kassetas, the state police chief. "It's another thing for a teacher or staff member to intervene."

Masterson, the social studies teacher, has taught at Berrendo for 10 years. The superintendent told NBC News on Wednesday that Masterson has been instructed not to speak to reporters. The school district and prosecutors are also declining media requests, citing the investigating.

The teacher did speak briefly with The Albuquerque Journal newspaper newspaper on Tuesday night. 

"It was a harrowing experience," he said. "All I can say was the staff there did a great job."

Investigators searched the boy's home, but police had yet to release a motive. Kassetas said there was "preliminary information" that some students had been warned by the shooter, but he said police had not substantiated that.

Robert Gorence, a prominent Albuquerque lawyer, said he was representing the suspect, a seventh-grader who he said had been transferred to a psychiatric hospital in Albuquerque after a judge's order.

Gorence said the boy's family would issue a statement Wednesday.

Authorities also praised the students in the gym for making a calm, orderly exit. Officials credited previous school-shooting drills there for preparing teachers and students.

It was the second shooting at an American middle school in three months. In Nevada in October, a mathematics teacher was shot to death while trying to shield students from a 12-year-old boy who opened fire.

Two boys were wounded in that attack before the shooter took his own life.

n New Mexico on Tuesday night , an crowd of about 1,500 attended a prayer vigil at the Roswell Convention Center, where pastors spoke of healing and urged people to pray for the suspected shooter.

The governor said she had spoken to two students who were in the gym, and when she asked one of them how he was feeling, he told her, "I'm just trying to hold it in."

"He says, ‘I just don't want to let it out because then it won't stop,'" she said. "These are kids that need the help. They need someone to lean on. And make sure that they're getting this out so it just doesn't eat them up."