Scholarism's Joshua Wong released at High Court judge's instruction
Mr Justice Patrick Li Hon-leung granted the writ of habeas corpus to Wong's lawyers, telling police the 17-year-old Scholarism leader (pictured) had been held for an "unreasonably long" time. He urged police to "fairly" treat two other detainees.
The two - Federation of Students leaders Lester Shum and Alex Chow Yong-kang - were released at about 11pm.
Government lawyers told the court Wong's release might undermine other investigations, but the judge ruled a "broad implication for further investigation" was insufficient. While his detention had been "lawful", keeping him longer than needed was "unlawful".
After his release, Wong - who claimed he had suffered bruises during his arrest - said he would return "to join the fight" after taking a short rest.
His lawyer, Michael Vidler, said: "The Department of Justice was seeking to impose conditions on his release and the court wouldn't have that at all."
Police said the investigation was continuing and that it reserved the right to prosecute Wong.
Wong's parents complained their son's detention was "political persecution".
Watch: Who is Joshua Wong?