Authorities in Norway, where Krekar has had refugee status since 1991, had accused him of being involved in organising attacks in northern Iraq. The Oslo court made its ruling to release him on Monday.
US officials accuse Ansar al-Islam of having ties to al-Qaida, believed to have carried out the September 11, 2001 attack on the World Trade Centre in New York.
Krekar says he has not led Ansar al-Islam, made up of a few hundred fighters concentrated in northern Iraq, since May 2002.
Police arrested Krekar last Friday, raiding his Oslo apartment and taking a computer with which he allegedly planned Iraq-based attacks.
While technically cleared of suspicion, he must remain behind bars this week to await new evidence from the prosecution, which has launched an appeal.
Kurdish fighters inspect damage
after an attack on alleged Ansar
base in Iraq last April
Krekar, whose real name is Fatah Najmeddin Faraj, has already been taken into custody once in Norway, in March 2003. He was released a month later.
He was also arrested in the Netherlands in September 2002 and detained for four months, where he was questioned by US FBI agents before being released and sent to Norway.
German authorities accuse Ansar al-Islam of plotting to attack the German army hospital in Hamburg.
In the initial stages of the US-led war against Iraq, occupation and Kurdish forces destroyed Ansar al-Islam bases in the north. Dozens of fighters were also killed.
But US commanders claim the group has made a comeback, infiltrating Iraq from Iran and setting up operations in the Baghdad area.
US troops reportedly battled Ansar fighters last week in the northern Iraqi town of Mosul.
Norway has been seeking to expel Krekar to Iraq, having earlier turned down an extradition request from Jordan.
He has violated his residency terms in Norway, but the government has not found sufficient grounds to extradite him.