In this Jan. 6, 2017, image taken from a surveillance video, Zia Zafar follows consular officer Christopher Ashcraft through a parking garage to his vehicle in Guadalajara, Mexico, before Zafar is seen on video shooting into the windshield of Ashcraft's car. (AP)

A U.S. citizen studying in Mexico who tried to kill a U.S. diplomat there will spend at least a decade in prison after pleading guilty Friday.

Christopher Ashcraft, vice consul at the U.S. Consulate in Guadalajara, was leaving a gym on a Friday evening in January 2017 when Zia Zafar approached his car from a garage ramp and fired one shot inside.

Zafar did not know Ashcraft but had figured out that he worked at the consulate, according to prosecutors. The 33-year-old from Chino Hills, Calif., was in Mexico on a student visa.

“I am guilty of whatever I did,” Zafar said in U.S. District Court in Alexandria on Friday afternoon. He spoke haltingly and seemed confused by some questions. His public defender, Whitney Minter, said Zafar was only recently deemed competent because of his new medications.

Zafar nearly went to trial to argue that he was not guilty by reason of insanity, and Minter said two doctors would testify at sentencing about his mental problems.

“We do still believe that there is an argument that Mr. Zafar was not able to understand the wrongfulness of his actions at the time,” she said in court Friday.

Mexican officials have said Zafar arrived in Guadalajara in late November 2016. A spokesman at the Autonomous University of Guadalajara has said Zafar was enrolled there.

Zafar had been waiting inside the garage but moved outside when he saw a security guard, according to court documents. He wore a wig and sunglasses to disguise himself.

The bullet hit Ashcraft in his chest and remains lodged in his spine, Assistant U.S. Attorney Ronald Walutes said in court Friday. Shrapnel is embedded in his pectoral muscle.

Zafar pleaded guilty to attempted murder of an internationally protected person and discharging a firearm during a crime of violence; the latter charge carries a 10-year mandatory minimum.

“The Vice Consul was targeted and shot because he represented the United States,” G. Zachary Terwilliger, the U.S. attorney for the Eastern District of Virginia, said in a statement. “No one should doubt the resolve of law enforcement to steadfastly investigate and apprehend those who attack us.”

Sentencing is set for Nov. 7.