By Syed Raza Hassan

KARACHI, Pakistan (Reuters) - The mayor of Pakistan's largest city Karachi, accused of helping militants and instigating political violence, was released from prison on Wednesday after a court granted him bail in the last of 39 cases against him, his lawyer said.

Waseem Akhtar, a member of the Muttahida Qaumi Movement (MQM) which controls the metropolis of 20 million people, was greeted by crowds of jubilant party supporters on his release.

"The court granted bail to Mr Akhtar in a case pertaining to aiding alleged militants' medical treatment," his lawyer Khawaja Naveed told Reuters.

Akhtar was arrested in July shortly after his election as mayor, so his release means he is able to take charge of Karachi, Pakistan's economic powerhouse, effectively for the first time. But the dozens of outstanding cases against him remain.

Most relate to promoting telephonic addresses by MQM chief Altaf Hussain, who has ruled Karachi from self-imposed exile in London for decades but whose speeches have now been banned by courts as treasonous.

Eight of the cases center on Akhtar's alleged role in orchestrating political violence that paralyzed Karachi on May 12, 2007, claiming dozens of lives at the height of a crisis involving then-president Pervez Musharraf and the Supreme Court Chief Justice. The MQM was a Musharraf ally at the time.

Akhtar's arrest was part of a military-driven crackdown in Karachi, Pakistan's economic powerhouse. The MQM complains it is being unfairly targeted, but the military says the campaign is directed only against criminals and terrorists.

Karachi has seen frequent ethnic, political and sectarian violence, and while crime has dropped since the crackdown began in 2013, targeted attacks are still common.

Akhtar's MQM has dominated politics in the city for decades, but has come under increasing pressure since the crackdown, which has seen the party split into several factions.

Hussain now rules one of those factions, while Akhtar has shown allegiance to a new faction led by party leader Farooq Sattar that has dubbed itself the MQM-Pakistan, in a bid to distance itself from the party's overseas leaders.

(Writing by Asad Hashim; Editing by Mark Trevelyan)