While the United States authorities have tracked and prosecuted citizens who try to join the Islamic State, it is unclear how they will respond to Americans’ fighting the group, especially since some Kurdish militias in Syria have ties to groups the State Department classifies as terrorist organizations.

Behind the scenes, American officials have pressured the pesh merga to keep Americans out of the fight, according to American military veterans who have been in Iraq. After being contacted by The New York Times, the pesh merga released a statement saying it would no longer accept foreign volunteers. Other militias are still accepting Westerners.

The fight against the Islamic State is not the first time Americans have joined wars independent of their military. Pilots flew for the Allies in World War I and II long before the United States officially declared war. In the Spanish Civil War in the 1930s, Americans formed a contingent of more than 2,500 troops.

The decision to fight the Islamic State carries risks. Beyond being killed, captured or kidnapped and held for ransom, Americans could also get caught fighting with a group that is viewed as a terrorist organization by the United States government. John Walker Lindh, for instance, joined the Taliban to fight other Afghans during that country’s civil war but then was captured by American forces during the invasion after the Sept. 11, 2001, attacks. He was sentenced to 20 years in prison for providing services to the Taliban in Afghanistan and carrying explosives during a felony.

“These war zones are often foggy, and tough to tell friend from foe,” said Neil MacBride, a former United States attorney who has prosecuted similar cases. “U.S. citizens could risk running afoul of U.S. material support to terrorism laws if they took up with the wrong group.”

Mr. Maxwell said he went to Iraq in part because little was keeping him here.

After a solid career in the military, which included guarding the president at Camp David and training troops, he left the Marines in 2011. He drifted from job to job, working construction, tending bar and pedaling a bicycle taxi. He also worked as a security contractor guarding an American Consulate in Afghanistan, but left after seven months.