A judge will investigate claims that British intelligence agencies were complicit in the torture of terror suspects, William Hague, the foreign secretary, said tonight.

The move was welcomed by civil liberties campaigners and may put pressure on the Labour leadership candidate and former foreign secretary David Miliband, who was accused by Hague, while in opposition, of having something to hide.

Miliband has repeatedly rejected the accusation and broadly indicated that he or his officials may have been misled by foreign intelligence agencies about the degree of British complicity.

Hague's remarks appear to have caught the Foreign Office by surprise, as no details were yet available on how the inquiry will be conducted, its terms of reference or when it will start work.

Hague will come under pressure to ensure the inquiry is public and comprehensive. He first called last year for an independent judicial inquiry into claims that British officials had colluded in the torture of Binyam Mohamed, the former Guantánamo detainee and a UK resident.

Mohamed claimed that he was tortured by US forces in Pakistan and Morocco, and that MI5 fed the CIA questions that were used by US forces.

Philippe Sands QC, professor of law at University College London, said tonight: "To restore trust in government, both here and abroad, and to get to the truth, the inquiry needs to be deep and broad and as open as possible. It should address, in particular, who authorised what and when and why, what the relevant legal advice said, and how it related to any change in US practice in 2002 and 2003."

Tayab Ali, a London solicitor who represents a number of men alleging torture, said the inquiry presented "a significant and precious opportunity" for the British public to understand their country's role in torture.

He Ali added: "It is essential that the inquiry is credible. It should be as open as possible, led by a judge and those affected should be properly represented. Anything less is likely to mean that the inquiry will fail in providing proper answers and holding those responsible to account for their actions."

Hague's statement redeems a pledge that both he and his then Liberal Democrat opposite number, Ed Davey, made in opposition. Hague told the BBC: "We have said again in the coalition agreement that we want a judge-led inquiry. So will there be an inquiry of some form? Yes, both parties in the coalition said they wanted that. Now what we're working on is what form that should take."

The coalition agreement published today by the government does not explicitly call for a judicial inquiry; it simply states: "We will never condone the use of torture."

Hague criticised the Labour government last year for failing to provide straightforward answers after the high court upheld one of Mohamed's claims. This was that the security services had put questions to him, through the US, even during a two-year period when they did not know where Mohamed was being held, according to Hague.

"So far ministers have stuck to the mantra that 'we never condone, authorise or co-operate in torture'," Hague wrote. "But this does not dispel any of the accusations. If anything, there is now a direct and irreconcilable conflict between such ministerial assurances and the account given by Mr Mohamed. That must be resolved."

He added: "We cannot sweep these allegations under the carpet. Until the full facts are known, Britain's name and reputation will be dragged through the mud – not least by the terrorists and extremists who will exploit these allegations for their own propaganda.'

"It is vital to remember that torture does not help us defeat terrorists; it helps them to try to justify their hostility to us."

The inquiry to which Hague has now committed himself will need to find a way of offering immunity to anyone who comes forward to give evidence. Although immunity deals are rarely granted to those who are complicit in torture, lawyers who advised Tory shadow ministers in the run-up to the election concluded that it is possible. Such a deal would be of clear benefit to the two MI5 and MI6 officers who are currently at the centre of a Scotland Yard investigation into their alleged criminal wrongdoing.

An inquiry may also help to resolve the many civil cases being brought by victims of torture and rendition. Government lawyers are expected to offer out-of-court settlements worth millions of pounds after the court of appeal this month dismissed an attempt by MI5 and MI6 to suppress evidence of alleged complicity.