WASHINGTON — A 21-year-old Hispanic man arrested after shots were fired near the White House was charged Thursday with attempting to assassinate President Barack Obama, a justice department official said.

Oscar Ortega-Hernandez was arrested by Pennsylvania state police on Wednesday following last week's shooting incident. Obama and his wife Michelle were in California at the time of the incident, and no one was injured.

Ortega-Hernandez -- from the western state of Idaho -- was charged in a US federal court in Pittsburgh, where a judge ordered that he remain in police custody, the official said. He could face life in prison if convicted.

According to court filings obtained by AFP, one of the suspect's friends said Ortega-Hernandez saw Obama as the "devil" and was "preparing something."

The witness said the suspect had said Obama "needed to be taken care of" and had pledged he would "not stop until it's done."

Ortega-Hernandez was due to be transferred "within a few days" to Washington, federal prosecutors said.

He was arrested at a hotel near Indiana, Pennsylvania, after gunshots were heard late Friday near the White House, about 600 to 700 yards (meters) away on Constitution Avenue, Secret Service special agent Edwin Donovan said.

Within five minutes of the shooting, authorities located an abandoned vehicle on Constitution Avenue, which runs along the north border of the Washington Mall.

From Constitution Avenue, a shooter would have an clear line of sight to the White House, across the Ellipse and the South Lawn of the presidential mansion.

Traffic is not restricted on Constitution Avenue and members of the public can approach the wrought iron fence at the bottom of the South Lawn on foot.

Obama, his wife, their two daughters, and the first lady's mother live at the White House, which is one of the world's most closely guarded buildings.

Because the gunshots were heard so near the White House, the Secret Service launched an investigation and on Tuesday morning found damage to an exterior window of the White House.

"A round was stopped by ballistic glass behind the historic exterior glass. One additional round has been found on the exterior of the White House," Donovan said Wednesday.

The White House's southern facade has three levels. On the ground floor are offices, the Map Room and rooms where the White House china is on display.

On the main floor several rooms have south facing windows, including the East Room, where presidential press conferences are held; the Blue, Red and Green Rooms, named after their dominant color schemes; and the State Dining Room.

On the top floor are the private living quarters of the president and his family. The residence's main bedroom, a dining room, a reception room and the Lincoln bedroom all have windows facing south.