A Somali-American who traveled by bus from Minneapolis to New York City with three other men and then tried to board a flight for the Middle East was charged Thursday in St. Paul with lying to the FBI during a terrorism investigation.

Hamza Ahmed was arrested Thursday morning in the Twin Cities by FBI agents and appeared Thursday afternoon before U.S. magistrate Steven Rau in federal court. He was ordered into custody pending a detention hearing on Monday.

The three men who traveled with Ahmed have not been arrested; a spokesman for the U.S. attorney's office in Minneapolis declined to comment on their whereabouts because of an ongoing investigation.

Ahmed is the latest in a string of suspects pursued by federal authorities who are investigating Twin Cities Somali-Americans who attempted to travel to the Middle East and join Islamic extremist organizations fighting there. In November, an Inver Grove Heights man was arrested by FBI agents at Minneapolis-St. Paul International Airport en route to the Middle East, and a co-conspirator who evaded arrest the next day is now believed to be fighting for the Islamic State in Iraq and the Levant (ISIL).

On Thursday, authorities said Ahmed's case is unique because of the measures he took to avoid suspicion.

Evidence gathered by the FBI details those measures and describes a suspenseful pursuit that led agents from Minnesota to New York.

Ahmed and the three others, all between the ages of 19 and 20, arrived at JFK International Airport in New York Nov. 8, 2014, hoping to board flights, according to an FBI agent's affidavit in support of the criminal charge. Ahmed and one of the men, identified as "M.F.," were booked on a flight to Istanbul, while the two others were booked to fly from JFK to Athens via Moscow.

Of the four men, Ahmed came within minutes of being able to leave the country. By the time federal customs and border agents at JFK had identified him as suspicious, he had already boarded his flight. But the plane had not left the gate, and agents were able to enter the aircraft and escort him off. Meantime, federal agents prevented the other men from boarding their flights.

Under questioning by FBI agents, Ahmed said he was traveling alone and used his own money to buy his ticket, according the affidavit. He denied knowing the man identified as M.F. and another known as "H.M.M.," even though they had also traveled from the Twin Cities to New York.

Ahmed was also shown a photograph of a man known to have traveled to Syria in early 2014 and told agents that he knew the man — identified only as "H.A.M." — from Burnsville High School. He said he had heard rumors from his mosque that the man had traveled to Syria, the agent stated.

Ahmed was interviewed a second time by agents who told him they were conducting a terrorism investigation and that it is a federal crime to lie to them. He told them that he took a Greyhound bus to New York and planned to vacation in Madrid alone for four days.

But his itinerary raised suspicions: It made little sense for him to fly as far east as Istanbul and then fly back to Spain. When he was again shown photographs, he admitted recognizing "M.F." from the bus, but denied they were traveling together, the affidavit states.

As the interview concluded, Ahmed said, "The truth is I really don't know these people," referring to the three others.

But video footage at the bus station showed Ahmed and M.F. arriving together in a vehicle, checking in and sitting together for about 30 minutes, and finally boarding the bus together, according to the FBI affidavit. In addition, Ahmed and the others each purchased their bus tickets within a 16-hour period in the days before their trip, and two of them bought their tickets online using the same computer or mobile device, an agent stated.

"Any person has a right to remain silent or consult an attorney when speaking with federal agents," said Andy Luger, U.S. attorney for Minnesota. "However, this office will continue to prosecute those who lie to federal agents and impede criminal investigations into suspected terror activity."

Ahmed also left evidence that linked him to H.A.M., the man from Burnsville who'd left earlier for Syria. Agents who reviewed his public Twitter account found a series of messages between the pair. In a December 2013, exchange, H.A.M. told Ahmed, "I love you for the sake of Allah." Ahmed replied, "Lol my bro I love you." .