A Fremont man who told friends that America was his enemy and that he was “content to die” for an al Qaeda-linked group in Syria has been charged with attempting to provide material support to a terrorist organization, federal prosecutors said Thursday.

Adam Shafi, 22, was arrested July 3, four days after federal agents stopped him from boarding a flight to Turkey, and has been in jail since then, prosecutors said. He pleaded not guilty to the terrorism charge Thursday in federal court in San Francisco and is scheduled for a hearing Tuesday on the government’s request to hold him without bail.

In court papers unsealed Thursday, an FBI agent said Shafi told a friend in a wiretapped phone call in June, 2½ weeks before his arrest, “I just hope Allah doesn’t take my soul until I have at least, like, a couple gallons of blood that I’ve spilled for him.”

Shafi is charged with attempting to provide material support or resources to al-Nusra Front, a hard-line Sunni Islamic faction aligned with al Qaeda that is fighting the Islamic State in Syria and is designated by the federal authorities as a global terrorist entity.

In a statement Thursday afternoon, his lawyer declared Shafi innocent.

Lawyer: ‘No evidence’

“There is no evidence that he was planning to do anything but fly to Istanbul, which is where he had been the year before for two days where he attempted to help the refugees and returned home,” said Joshua Dratel, a veteran criminal defense attorney. “There is no statement by him that he was intending to go to Syria or join any designated terrorist group. ... His intentions were never criminal nor violent.”

Shafi was stopped at San Francisco International Airport on June 30, while trying to board a flight to Istanbul, a common entry point into Syria for foreign fighters hoping to join terrorist organizations such as al-Nusra Front and the Islamic State, officials said.

Against gay marriage

Questioned by federal agents, Shafi said he no longer wanted to live in the United States because of its politics and direction — citing the recent Supreme Court decision legalizing same-sex marriage — and preferred to live in a nation of like-minded fellow Muslims, FBI agent Christopher Monika said in a court affidavit. But he said Shafi denied intending to join a terrorist organization and said he wanted to help Syrian refugees.

Later that evening, in a secretly recorded phone call, Shafi said he had lied to the agent, Monika reported. “What kind of idiot would say yes” when asked if he planned to join a militant group, Shafi told another person, believed to be one of his relatives. “Yes, that is exactly why I was going.”

Asked about that conversation Thursday, Dratel, Shafi’s lawyer, said the remarks were taken out of context. He said Shafi’s frame of mind could be understood better from another recorded conversation later the same evening, in which he told another friend that the agent had asked whether he intended to join a terrorist organization.

Remarks misconstrued

“Even if I was going to do that, what the hell?” Shafi replied, according to the lawyer in an interview. He meant that no would-be terrorist would ever admit his intentions to the FBI, Dratel said.

In his statement, Dratel said Shali’s case “represents a perfect opportunity for the government to make good on its professed commitment to finding another way, other than criminal prosecution, to address instances of young Muslims being motivated by the humanitarian crisis in Syria to act in some way to alleviate that suffering. That is what motivated Adam Shafi.”

Shafi’s family lives in a large two-story house on a street corner of a residential subdivision in Fremont. Several cars were parked there Thursday, including a white Toyota Prius registered to Shafi. An unidentified man who answered the phone there referred all questions to Dratel.

“They just seem like they’re a good, quiet, traditional Muslim family,” with parents in traditional Muslim attire and six or seven children, said Rakesh Sharma, who lives down the street and is president of the local homeowners’ association. He said the family had lived there for at least 20 years. “Just learning the news is a surprise and a shock.”

Shafi graduated in 2011 from Mission San Jose High School, a high-achieving campus in an upscale area of Fremont, said Principal Zack Larsen. His father, Sal Shafi, is president and chief executive officer at ESG Consulting in Santa Clara, an international computer consulting firm that does extensive charity work providing technical training to underprivileged people.

Monika said the government first became aware of Adam Shafi in August 2014, when he disappeared during a family trip to Cairo. Sometime thereafter, officials began following his movements and monitoring his phone calls.

America the enemy

A few weeks before he was stopped at the airport, in a June 5 call to another friend, Shafi said he considered America to be the enemy, Monika said. He also drew a distinction between al-Nusra Front and the Islamic State, or ISIS, which he considered too bloodthirsty, the agent reported. Monika quoted Shafi as saying that ISIS blew up markets and had beheaded an al-Nusra leader, while al-Nusra fought only those religious groups that fought al-Nusra.

“I am completely fine dying with these guys,” Shafi said in the recorded call.

Disappeared in Cairo

After his disappearance in Cairo, Shafi’s father and another relative contacted the U.S. Embassy, and the relative relayed a text message in which Shafi said he had gone to “protect Muslims,” Monika said. He said Shafi’s father was concerned that his son may have been following “some extreme imams online,” in the agent’s words.

Shafi returned to his family the next day, Monika said. He said a friend of Shafi, described by the friend’s brother as a possible terrorist recruit, told the FBI later that he and Shafi had traveled to Turkey but decided to return because Shafi “wasn’t feeling it.”

He is among hundreds of Americans whom the U.S. government has accused of joining or financially supporting terrorist organizations since the attacks of Sept. 11, 2001. They include John Walker Lindh, a Marin County man captured in Afghanistan in November 2001 after joining Taliban rebels. Facing a potential life sentence on terrorism charges, Lindh pleaded guilty to aiding the Taliban in 2002 and received a 20-year sentence.

If convicted, Shafi faces a maximum sentence of 20 years in prison and a fine of $250,000.

Al-Nusra, the organization he allegedly was attempting to join, is an al Qaeda affiliate dedicated to overthrowing the Syrian government and establishing an Islamic state in the country. It has also fought the Islamic State, which has declared its own religious caliphate in the region. The U.S. government classified al-Nusra, Arabic for “the support,” as a terrorist organization in December 2012.

San Francisco Chronicle staff writers Kevin Fagan and Peter Fimrite contributed to this report.

Evan Sernoffsky and Bob Egelko are San Francisco Chronicle staff writers. E-mail: esernoffsky@sfchronicle.com; begelko@sfchronicle.com Twitter: @EvanSernoffsky; @egelko