The special tribunal for Lebanon, which began work on March 1, is based in The Hague, Netherlands.
Celebratory gunfire erupted in Beirut as soon as Fransen announced his decision.
The UN ruling came two days after Daniel Bellemare, the special prosecutor in charge of the case, handed his recommendation on the generals' fate.
Bellemare had advised that Mustafa Hamdan, the former head of the presidential guard; Jamil al-Sayyed, the security services director; Ali al-Hajj, the domestic security chief; and Raymond Azar, the former military intelligence chief, be freed "with immediate affect".
The four men were suspected of being behind the blast which killed al-Hariri.
A Lebanese investigating judge lifted the arrest warrants against the generals earlier this month, but ordered that they remain in jail pending the UN tribunal's decision.
Al-Hariri was killed along with 22 others in a bomb blast on the Beirut seafront on February 14, 2005, stirring a political crisis and leading to the withdrawal of Syrian troops in Lebanon after a 29-year presence.
A UN investigative commission had said there was evidence that Syrian and Lebanese intelligence services were linked to the killing.
Damascus denied any involvement.
In the statement read out at the Hague on Wednesday by Fransen, Bellemare noted "that a person may not be placed in provisional detention unless he is willing to indict in a very short time frame".
He considered "the evidence available to him currently is not sufficiently credible to request the maintenance and detention of those persons", Fransen said.
|Al-Hariri was killed along with 22 others in a blast in Beirut in February 2005 [Reuters]
The generals can be indicted at a later stage, however.
Al Jazeera's Rula Amin, reporting from Beirut, said: "It's a very significant decision, and the Lebanese government has already said that it would follow whatever decision the UN tribunal stated."
Saad Hariri, the son and political heir of al-Hariri and leader of Lebanon's parliamentary majority, welcomed the UN decision, saying it showed that the tribunal had no political agenda.
"I ... don't feel one iota of disappointment or fear over the fate of the international tribunal," Hariri said in a televised address.
"What has happened is a clear declaration that the international tribunal has started work and it will reveal the truth."
Supporters of the freed generals fired rifles into the air in their home towns and gave away sweets and slaughtered sheep on Wednesday.
The men received an emotional welcome on their return home from Roumieh jail, northeast of Beirut.
Al-Sayyed, addressing a crowd outside his home, criticised the Lebanese judiciary for holding them without charge.
"We don't want vengeance, we just want those who committed this crime of arbitrary political detention to be held accountable," he said.
Samar al-Hajj, al-Hajj's wife, told Al Jazeera: "They are free men, free officers, and we tell those who claim the opposite that they are not accused who are not found guilty, they were merely a screen over the truth. Now, we should find the truth."