Two men arrested at New York's John F Kennedy Airport have been charged with conspiring to commit an act of international terrorism.
US authorities say they intended to join a jihadist group in Somalia and kill American troops overseas.
Mohamed Mahmood Alessa, 20, and Carlos Eduardo Almonte, 24, were held before they could board separate flights to Egypt and then continue to Somalia.
They are due to appear on Monday in a federal court in Newark, New Jersey.
US justice officials say state and federal law enforcement agents have been investigating Mr Alessa, of North Bergen, New Jersey, and Mr Almonte, of Elmwood Park, New Jersey, since 2006.
The pair face charges of conspiring to kill, maim, and kidnap persons outside the United States by joining al-Shabab, a militant group based in Somalia and linked to al-Qaeda. Al-Shabab was designated a terrorist group by the US in 2008.
A New York Police Department undercover officer is said to have recorded conversations with the men - both of them reportedly US citizens - in which they spoke about killing Americans.
They are also alleged to have watched online footage of attacks on US troops and suicide bombings, and played recordings of Anwar al-Awlaki - a radical American Muslim cleric of Yemeni descent linked to a series of attacks and plots across the world - promoting violent jihad and justifying the killing of civilians.
The two men are alleged to have planned their trip to Somalia for several months, saving thousands of dollars, practicing for combat at paintball facilities and using virtual-reality games, and acquiring equipment and clothing they could use when they joined al-Shabab in Somalia.
New York City Police Commissioner Raymond Kelly said in a statement: "We are also concerned that should they remain undetected and fail in their foreign aspirations that they might strike domestically, as was discussed as a possibility in this case."
This apparently refers to an alleged comment by Mr Alessa, who reportedly said: "We'll start doing killing here, if I can't do it over there."
The government of Somalia has welcomed the arrests, with a spokesman for the ministry of information telling AP: "Foreign terrorists here are an obstacle to lasting peace in Somalia. So we welcome the move and we are calling on all governments to take such steps against al-Shabab and all terrorists at large."
The arrests follow two failed attacks in the US in recent months: an attempted car bombing in Times Square last month and the attempted Christmas Day bombing of a Detroit-bound airliner.