This Nov. 21, 2011 file artist rendering shows accused White House shooter Oscar Ortega-Hernandez, center, before Magistrate Judge Alan Kay, left, in federal court in Washington. The Idaho man pleaded guilty Wednesday to firing eight shots at the White House. From left are, U.S. Assistant Attorney George P. Varghese, a public defender David Bos, Ortega-Hernandez, and Judge Kay. (Dana Verkouteren/AP)

An Idaho man pleaded guilty Wednesday to opening fire on the White House in November 2011.

No one was injured, but two members of President Obama’s family were there when Oscar R. Ortega-Hernandez began shooting, according to court documents filed Wednesday. Ortega-Hernandez admitted firing eight rounds from a semiautomatic assault rifle into the second and third floors of the White House.

The 22-year-old had been scheduled to go to trial in federal court in Washington on charges that included attempted assassination of the president. Instead, he pleaded guilty to using a firearm during a crime of violence and to damaging the White House and putting “lives in jeopardy.”

He faces up to 27 1 / 2 years in prison, according to federal sentencing guidelines.

Ortega-Hernandez teared up at the courtroom lectern as he took responsibility for the shooting.

“Oscar is really remorseful about what he did,” his attorney, Robert Feitel, said after the hearing. “Oscar was laboring under serious stress, and his judgment was clouded.”

Feitel declined to comment about whether Ortega-Hernandez had been receiving mental-health treatment. His guilty plea follows Monday’s shooting rampage at the Washington Navy Yard that killed 12 people. Authorities said the Navy Yard shooter, Aaron Alexis, was battling mental-health issues.

“Firing an assault rifle at the White House to make a political statement is terrorism, plain and simple,” U.S. Attorney Ronald C. Machen Jr. said in a statement. “As we have seen this week, gunmen who come to the nation’s capital bent on violence can inflict terrible damage. This act of cowardice put lives at risk.”

In the months leading up to the White House shooting, Ortega-Hernandez had become agitated, authorities said. He told friends that the federal government was seeking to control Americans by implanting global positioning chips in children, according to the plea agreement.

Acquaintances told authorities that Ortega-Hernandez had told them that he “needed to kill” the president that Obama was “the antichrist.”

In October 2011, he recorded two videos of himself in which he called for a revolution, according to the statement of offense signed by Ortega-Hernandez. He then drove 2,200 miles from his home in Idaho Falls to Washington.

On the evening of Nov. 11, he stopped his 1998 Honda Accord on Constitution Avenue NW shortly after passing the entrance to the Ellipse. He began firing a semiautomatic rifle equipped with a telescopic sight.

Driving away moments later, Ortega-Hernandez lost control of the car and crashed near the ramp to the Theodore Roosevelt Memorial Bridge. He fled on foot and was arrested at a hotel in western Pennsylvania after a five-day manhunt.

Obama and first lady Michelle Obama were in California at the time of the shooting. The U.S. attorney’s office declined Wednesday to identify which two members of the “First Family” mentioned in court documents were at the White House that evening.

Federal investigators recovered bullets from the White House, including from the window frame of the Truman Balcony. One bullet struck the roof within close proximity of where U.S. Secret Service officers were on duty.

Prosecutors told U.S. District Judge Rosemary M. Collyer that they may ask Ortega-Hernandez to pay restitution to cover more than $97,000 in repairs to the White House.

Ortega-Hernandez’s sentencing is set for Jan. 10.