WASHINGTON — Federal authorities on Thursday charged a 21-year-old Idaho man with attempting to assassinate President Obama — saying he had told one friend that the president was “the Antichrist” and that he “needed to kill him,” according to a complaint filed in federal court.

The man, Oscar Ramiro Ortega-Hernandez of Idaho Falls, who is accused of spraying bullets from an assault rifle at the residential floors of the White House last week, was also “convinced the federal government is conspiring against him” and had become “increasingly more agitated” before he disappeared from Idaho last month, the complaint said.

The complaint was filed in conjunction with a brief appearance by Mr. Ortega-Hernandez in a federal courthouse in Pittsburgh on Thursday afternoon. He had been arrested on Wednesday at a hotel near the town of Indiana, Pa., and officials intend to bring him back to the District of Columbia to face the assassination charge, which carries a maximum sentence of life in prison.

Mr. Ortega-Hernandez was shackled and dressed in a white prison-issue jumpsuit. He spoke only briefly during the hearing, muttering “yes ma’am” when asked by a magistrate judge if he understood his legal rights.