LAS VEGAS — A British man arrested at a weekend Donald Trump rally in Las Vegas tried to grab a police officer’s gun so he could kill the presidential candidate after planning an assassination for about a year, according to authorities.

U.S. Secret Service agents said Michael Steven Sandford approached a Las Vegas police officer at the campaign stop to say he wanted Trump’s autograph, but that he then tried to take the weapon.

A complaint filed Monday in U.S. District Court in Nevada charges Sandford, 20, with an act of violence on restricted grounds. He was denied bail during a court appearance later in the day. His court-appointed attorney said he was living out of his car and in the country illegally after overstaying a visa.

Sanford has not entered a plea.

The arrest happened relatively quietly at a campaign stop seen as peaceful compared to the mayhem at the presumptive Republican nominee’s recent events in San Jose, California, and Albuquerque, New Mexico.

Gregg Donovan was among about 1,500 gathered Saturday to see Trump at the Treasure Island casino on the Las Vegas Strip. For the event, he donned the top hat and red jacket that made him recognizable in his former job as swanky Beverly Hills’ official greeter for more than a decade.

Donovan said he didn’t know about the charge against Sanford until he saw news reports. But he recognized him because the two had stood in line together for nine hours waiting to get into the Trump event. Sanford even held Donovan’s spot in line for a bathroom break.

“I was No. 5, and he was No. 4,” Donovan said.

They spoke, Donovan said, though Sanford didn’t say much and seemed “strange.” Donovan didn’t elaborate on what made Sanford seem odd.

After waiting, they passed through metal detectors manned by Secret Service, police and casino security officials.

Federal Magistrate Judge George Foley said in court Monday that Sandford was a potential danger to the community and a flight risk. Sandford wore leg irons and appeared to tremble during the hearing.

Heather Fraley, his assigned public defender, said Sandford appeared to be competent. She said he hadn’t been diagnosed with a mental illness but that he has autism and previously attempted suicide. He doesn’t have a job.

Sanford’s mother told court researchers that he was treated for obsessive compulsive disorder and anorexia when he was younger, and that he once ran away from a hospital in England, according to the public defender.

Fraley argued that Sandford should go to a halfway house because he didn’t have a criminal history, but the judge said he should stay in detention ahead of a July 5 court date.

Agents said Sandford told them he had been in the U.S. for about a year and a half, lived in Hoboken, New Jersey, and drove to the San Bernardino, California, area before coming to Las Vegas on June 16.

Sandford told officers he was convinced he would die in the assassination attempt. He said he also reserved a ticket for a Trump rally in Phoenix, scheduled for later Saturday, as a backup plan.

The criminal complaint said Sandford was arrested after grabbing the handle of an officer’s gun while trying to remove it from a holster.

Sanford told authorities that he went to the Battlefield Vegas shooting range the day before the rally and fired 20 rounds from a 9mm Glock pistol to learn how to use it. Police detectives who visited the range spoke with an employee who confirmed that he provided Sandford shooting lessons, according to the complaint signed by Secret Service Special Agent Joseph Hall.