Justice Hasnain Masoodi, who had earlier reserved order on the petition filed by Alam's counsel, quashed the PSA detention of the 45-year-old separatist leader.
Alam was arrested on April 17 in connection with the raising of Pakistani flags and chanting of anti-national slogans during a rally organised by hardline Hurriyat Conference to welcome Syed Ali Shah Geelani from New Delhi.
Police had registered a case against several separatist leaders including Bhat and Hurriyat Conference chairman Geelani for provocative activities including hoisting of Pakistani flag.
Alam was released in March -- soon after the PDP-led government came to power -- after over four years of detention in connection with the 2010 summer agitation in the valley.
His release had created a furore across the country and the issue had even figured in the Parliament proceedings with Prime Minister Narendra Modi making a statement on the floor of the house.