"The court ... has acquitted Mahmudi and so we are demanding his immediate release," Baghdadi Al Mahmudi's lawyer, Mabrouk Kourchid, said after the hearing.
"There is no legal reason to keep him in prison," he said. "(Mahmudi) should be released because his detention is illegal and the reasons are purely political."
Tunisian authorities gave no indication about whether they intended to free Mr Al Mahmudi. He remains the subject of two extradition requests from Libya, which he fled following the collapse of Muammar Qaddafi's regime.
Mr Al Mahmudi, 70, is appealing extradition on the grounds that he has applied for refugee status and could face execution if sent back to his homeland.
The former prime minister, who has been detained since his September 21 arrest on the southwestern border with Algeria, appeared in court after being transferred from prison by ambulance.
Although his extradition has been approved by Tunisian courts, the country's interim president, Fouad Mebazaa, last year declined to sign extradition papers and his successor Moncef Marzouki has told Tripoli he would be returned when conditions were in place for a "fair trial".
Libya is seeking Mr Al Mahmudi on charges of inciting rape in the town of Zuwarah in north-western Libya during the anti-Qaddafi revolution, his defence team has said.
"Tunisian authorities claim that the detention of the former Libyan prime minister is to ensure his security. That's just an excuse," said the lawyer, adding that the defence will file an official demand for Mr Al Mahmudi's release.
Tunisia provided refuge to tens of thousands of Libyan civilians who fled the months of fighting that led to the collapse of Qaddafi's regime.