The move would force the government to break its secrecy and reveal the most comprehensive list yet of those who have been imprisoned there.
Some of the hundreds of detainees being held at the US military base in Guantanamo Bay, Cuba, have been held as long as four years. Only a handful have been officially identified.
Jed Rakoff, a US district judge in New York, ordered the US Defence Department on Thursday to release uncensored transcripts of detainee hearings, which contain the names of detainees in custody and those who have been held and later released.
Previously released documents have had identities and other details blacked out.
The judge ordered the government to hand over the documents by 3 March after the Defence Department said on Wednesday it would not appeal against his earlier ruling in the lawsuit filed by the AP.
On 23 January, Rakoff ordered the military to turn over uncensored copies of transcripts and other documents from 317 military hearings for detainees at the prison camp.
There were another 241 detainees who refused to participate in the Combatant Status Review Tribunals and the Defence Department said no transcripts exist of those hearings.
Held without charge
The US authorities now hold about 490 prisoners at Guantanamo on suspicion of links to al-Qaida or the Taliban.
Most have been held without charges since the detention centre opened four years ago, prompting complaints from human rights groups and others.
Dave Tomlin, assistant general counsel for Associated Press, said: "AP has been fighting for this information since the fall of 2004. We're grateful to have a decision at last that keeping prisoner identities secret is against the public policy and the law of this country."
"There are still people there who don't have a lawyer and we don't know who they are. They have disappeared"
president, Centre for Constitutional Rights, New York
The military has never officially released the names of any detainees except the 10 who have been charged.
Michael Ratner, president of the Centre for Constitutional Rights in New York, which represents about 200 detainees, said most of those that are known emerged from the approximately 400 civil suits filed on behalf of prisoners by lawyers who got their names from family or other detainees.
Ratner said: "They have been very resistant to releasing the names. There are still people there who don't have a lawyer and we don't know who they are. They have disappeared."
The Defence Department earlier released transcripts after the AP filed a suit under the Freedom of Information Act, but the names and other details of detainees were blacked out.
Navy Lieutenant-Commander Jeffrey Gordon, a Pentagon spokesman, said the Defence Department "will be complying with the judge's decision in this matter".
Law experts said the case has wide-ranging implications.
Jonathan Hafetz, of the New York University School of Law, said: "The government has tried to maintain Guantanamo as a black hole since they opened it.
"This is bringing it within the mainstream of the justice system and says we're not going to have secret detentions at Guantanamo."
"The government has tried to maintain Guantanamo as a black hole since they opened it"
New York University School
In his ruling last month, Rakoff rejected government arguments that releasing the detainees' names from transcripts should be kept secret to protect their privacy and their families, friends and associates from embarrassment and retaliation.
Megan Gaffney, a spokeswoman for the US Attorney in the Southern District of New York, said the judge had given the government a month to decide whether to appeal and that the US Solicitor General decided not to pursue the case further.