The shooting at Berrendo Middle School in Roswell took place in a gym where students had gathered to stay warm from the frigid weather outside before the start of class, Governor Susana Martinez told reporters.
"The shooter was quickly stopped by one staff member who walked right up to him and asked him to set down the firearm, which he did," Martinez said.
Police said they took the shooter into custody at the school, which was placed on lockdown. A police lieutenant who had been dropping off his child helped in "securing" the shooter, Martinez said.
The two students wounded in the attack were a 12-year-old boy in critical condition and a 13-year-old girl in serious condition, Martinez said at a news conference. A hospital official had earlier put the boy's age at 14.
The wounded students were taken to a local hospital, where they were stabilized. They were then flown by helicopter to University Medical Center in Lubbock, Texas, about 150 miles east of Roswell, because that facility has a Level 1 trauma center, said hospital spokesman Eric Finley.
The incident was the second to take place at a middle school in three months, after a 12-year-old boy opened fire with a handgun at his middle school in Sparks, Nevada, in October, killing a teacher and wounding two other students before shooting himself to death.
It comes amid a national debate on gun control, after a gunman shot to death 20 students and six adult staff members at Sandy Hook Elementary in Newtown, Connecticut, in December, 2012. Following that attack, President Barack Obama called for sweeping new gun control measures.
Most of Obama's proposals were defeated in Congress, but his administration proposed new regulations this month aimed at clarifying restrictions on gun ownership for the mentally ill and bolstering a database used for firearms background checks.
GUN CONCEALED IN BAG
The 12-year-old boy who opened fire at the school arrived with a shotgun concealed in a bag, said New Mexico State Police Chief Pete Kassetas, who commended adult staff at the school for their quick response to the shooting.
"It's one thing for an armed state police officer to enter the school and do his or her job," Kassetas said. "It's another thing for a teacher, staff member to intervene in a situation like this."
The wounded boy was shot in the face, students told the Albuquerque Journal. Sixth-grade student Anyssa Vegara told the paper she had been talking to a security guard when she heard a shot.
"I turned around and all I saw was someone on the floor with their arm bleeding," Anyssa told the Journal.
Kathy Sigala, a parent, told Roswell television station KOBR, an NBC affiliate, that she was made aware of the shooting by a phone call from an office colleague.
"It was scary, it was freaky," Sigala told the station. "We just can't believe that it would happen here."
Roswell, a city of 48,000 people in southeastern New Mexico, is best known for its association with UFO lore because of the 1947 crash at a nearby site of an object UFO proponents believe was an alien ship. The U.S. military says materials recovered near the site were from an experimental surveillance craft.