More than 25,000 Nigerian inmates, or 65% of the prison population, have never been convicted of a crime but remain jailed because of delays in the justice system, missing police files, absent witnesses and prison mismanagement.
Bayo Ojo, the justice minister and attorney-general, said on Thursday: "We have embarked on a massive decongestion of prisons and 10,000 prisoners have been cleared for release. Some are already out, some are in the process of being freed."
He said those being freed included thousands who were accused of minor crimes and had spent longer in jail awaiting trial than they would have served if convicted.
The average waiting time for a trial is five to 10 years.
Ojo spoke on the sidelines of an event to launch a $64 million fundraising campaign for prison reform that would be carried out by the government and Nigerian non-governmental organisations with help from the UN Office on Drugs and Crime.
The funds would be used to renovate six pilot jails, train prison staff, improve data management and introduce rehabilitation programmes for prisoners, among other measures.
Speakers at the event, including Olusegun Obasanjo, the president and a former political prisoner, described Nigerian jails as violent, overcrowded, filthy, rife with diseases and unable to provide decent food to inmates.
They said that, in most cases, prisoners were being hardened by their experiences behind bars because of the harsh conditions and a dearth of rehabilitation opportunities.
Ojo said he expected the 10,000 to be free by the end of this year, after which the cases of the remaining 15,000 prisoners awaiting trial would be considered.
"These cases are more complex because most of those 15,000 are armed robbery suspects so you can't let them out on to the streets just like that," he said.
The strategy would be to bring the suspects to trial as quickly as possible.
However, thousands of them cannot be tried because their police files have been lost.
Ojo said those suspects would be released to "halfway houses" where they would spend two years in rehabilitation and professional training before gaining their freedom.
Six halfway houses are due to be created, one in each of Nigeria's geo-political zones.
A government-commissioned survey published last September found that in four out of 10 cases, prisoners awaiting trial were ordered to be jailed indefinitely by magistrates under a "holding charge".
Yet such a charge does not exist in any of Nigeria's legal codes.
Ojo said a bill going through parliament would address this problem by banning indefinite detention without trial.
He also said the government was working on a police reform programme that would help improve Nigeria's poorly trained, badly paid police who are more often found extorting money from drivers at illegal roadblocks than investigating crimes.