A federal judge ruled Saturday that the U.S. military must provide legal counsel to an American citizen who was picked up months ago on the Syrian battlefield and accused of fighting with Islamic State militants.

The unidentified American, who has not been charged, surrendered to U.S.-backed fighters in Syria around Sept. 12 and is currently being held in Iraq as an unlawful enemy combatant.

The American Civil Liberties Union filed a court petition challenging his detention and asking to act on his behalf to provide him access to legal counsel.

Late last month, the U.S. government acknowledged that it has detained an American citizen accused of fighting with IS for months without fulfilling his request to see a lawyer. Responding to a court order, the government said the man picked up on the Syrian battlefield indicated he was willing to talk to FBI agents but "felt he should have an attorney present."

In her ruling, U.S. District Judge Tanya Chutkan denied the Defense Department's motion to dismiss the matter and ordered the military to let the ACLU "immediate and unmonitored access to the detainee" so that it can determine whether he wants the ACLU to represent him. The judge also ordered the Defense Department not to transfer the detainee until the ACLU tells the court of the detainee's wishes.

"This is a landmark ruling that rejects the Trump administration's unprecedented attempt to block an American citizen from challenging his executive imprisonment," said Jonathan Hafetz, senior staff attorney for the ACLU. "Ensuring citizens detained by the government have access to a lawyer and a court is essential to preserving the Constitution and the rule of law in America."

Kathryn Wyer, an attorney in the Justice Department's civil division, earlier told the court that the U.S. military was working "diligently" on the matter, but had not yet decided what to do with the detainee. Wyer cited case law stating the executive branch should be given a reasonable period of time to determine a detained individual's status.

The government said that during questioning that FBI special agents advised the detainee of his right to remain silent even though he might have spoken earlier to other interrogators. That was an apparent reference to intelligence agents who are believed to have questioned the detainee first. The government said the detainee also was advised of his right to an attorney.

But the government also acknowledged that the detainee said he "understood his rights and said he was willing to talk to the agents, but also stated that since he was in a new phase (of questioning), he felt he should have an attorney present."