A foreign student is facing deportation after threatening Donald Trump's life on Facebook

LOS ANGELES (AP) — An Egyptian flight student who was arrested after he wrote on his Facebook page that he would be willing to serve a life sentence for killing Donald Trump agreed Friday to leave the United States by July.

FILE - This undated file photo provided by Ohoud Ali Mohamed Nasr El Sayed shows her brother, Emadeldin, an Egyptian aviation student in the Los Angeles area. Emadeldin Elsayed, a 23-year-old aspiring pilot from Cairo, is expected to appear in immigration court Friday, March 4, 2016, to determine whether he should be deported after being investigated by federal agents for posting threatening comments on his Facebook page about Republican presidential candidate Donald Trump. (Ohoud Ali Mohamed Nasr El Sayed via AP, File) http://syndication.ap.org/AP.Distro.ContentBroker2/ContentBroker.aspx?contentid=24b6f14c97e22f0b920f6a7067009cdd&iid=6850cb09cfc74d1c9f67a39f1e99ffd8&rsn=0&recordid=6850cb09cfc74d1c9f67a39f1e99ffd8&filingId=5ac5d0bd18a149d88d5d92dff5e0d388&role=Preview&reldt=2016-03-04T07:20:16&media=Photo&sz=&dest=ak&trF=CAET764&ofn=Egyptian%2bStudent%2bTrump%2bThreat.JPEG&fmt=jpg&relativeUrl=jpg/2016/201603/04/24b6f14c97e22f0b920f6a7067009cdd.jpg&s3Key=preview.jpg&authToken=eNoti7sOwyAMAL8IZEwwYUDqr5RHJA8NEQQ1gz%2b%2bDF1uuTupTyTrAoZ90QOARUDJHHFLdJgtq%2bArKjwgqYBwKHp7oBWGXIo0LmsHZ2WOmNt5d07zbn280hx81rEwuNSuc%2fvI5BUbICvXN%2f6FcSB8RYeaNBrUu%2fsBk1Mtew%3d%3d An Egyptian flight student who was arrested after he wrote on his Facebook page that he would be willing to serve a life sentence for killing Donald Trump agreed Friday to leave the United States by July.

Immigration authorities will allow Emadeldin Elsayed, 23, to return home voluntarily instead of deporting him, as long as he departs by July 5. Elsayed has not been charged with a crime but had his visa revoked by the State Department and is being held at a Southern California jail.

His lawyer, Hani Bushra, told Immigration Judge Kevin Riley in Los Angeles that he may seek another bond hearing for the aspiring pilot from Cairo because he believes Elsayed's detention is illegal.

Bushra said after the hearing that he understands why the Feb. 3 Facebook post led to his client being investigated. But in the absence of criminal charges, Elsayed should be freed, the attorney said.

"He's being detained, I think, primarily because he's a Muslim and he's a Middle Easterner," Bushra said, adding that social media sites are teeming with similar comments. "This kid is going to become a poster boy for hating America."

Immigration and Customs Enforcement arrested Elsayed at his Los Angeles-area flight school on Feb. 12, eight days after the Secret Service interviewed him about his post on the Republican presidential front-runner.

U.S. officials often use immigration laws to quickly remove people from the country who are suspected of crimes rather than drag out a lengthy prosecution, said Claude Arnold, a recently retired special agent in charge of ICE's homeland security investigations in Los Angeles.

"It accomplishes the same goal: You neutralize the potential threat," Arnold said, adding that the goal is to protect Trump and public safety.

Threatening a presidential candidate is a crime, regardless of a person's immigration status, Arnold said.

"If you are a guest, you are more vulnerable if you do something stupid like that," he said.

Elsayed said in a phone interview earlier this week that Trump's comments about Muslims angered him, but he never intended to hurt anyone.

Donald Trump. AP Photo/John Minchillo Trump has used especially tough talk on immigration during his campaign. He has vowed to build a wall along the entire Mexican border and called for a temporary ban on Muslims entering the U.S.

Elsayed said the agent who interviewed him mentioned last year's shooting rampage by a Muslim couple in San Bernardino and the Sept. 11, 2001, terror attacks, which were carried out by Muslims who had sought flight training in the United States.

Elsayed said he would seek a refund of some of the $65,000 he spent to pursue his pilot's license and try to get it elsewhere.

Immigration authorities said the flight school tipped off investigators to Elsayed's Facebook post, Bushra said.

Alex Khatib, owner of Universal Air Academy, said he was not aware of the case until federal agents showed up to interview and later detain Elsayed.