Zambia's detained opposition leader is due to appear in court on treason charges, four months after his arrest for failing to make way for President Edgar Lungu's motorcade.

Hakainde Hichilema, who narrowly lost last year's presidential elections, was charged with treason for allegedly putting Lungu's life in danger.

The case has stoked political tensions in Zambia.

A lawyer from Hichilema's United Party for National Development (UPND) told the AFP news agency that the party expected the charges to be dropped and for Hichilema to walk free.

"They don't have a case against him. We are certain that he will come out tomorrow," the party lawyer, who declined to be named, told AFP on Sunday.

READ MORE: Neoliberalism, big capital and the Zambian crisis

Reuters, citing government and legal sources, said Hichilema is to be freed under a deal brokered by the Commonwealth secretary-general.

Patricia Scotland, the Commonwealth secretary-general, visited Lusaka last week and told reporters she had met Lungu and Hichilema separately and that the two leaders had agreed to a process of dialogue facilitated by her office.

'Public interest'

A government source told Reuters that the state would quash the case "in the public interest".

Hichilema and Lungu "are committed to burying their past and starting dialogue envisaged to help address some of the issues the opposition raised after the 2016 elections," the source said.

Political tension has been on the rise in Zambia, seen as one of Africa's more stable and functional democracies since Lungu's Patriotic Front (PF) beat the UPND in a presidential election marred by violence.

Hichilema, 55, says the election was rigged and has refused to recognise the president.

In July, Lungu invoked emergency powers, increasing police powers of arrest and detention after he blamed opposition parties for a string of arson attacks.

He has denied allegations of growing authoritarianism and has accused his rivals of trying to overturn the election result.

Lee Habasonda, a political science lecturer at the University of Zambia, said Hichilema's release would end mounting international pressure on Lungu's government.

"In the face of Zambia seeking international assistance, it is time to make such a move because the state does not lose anything by releasing the opposition leader and dealing with him in other ways," Habasonda told Reuters.

Police on Thursday freed another opposition leader, United Progressive Party leader Saviour Chishimba, after holding him in detention for a week on accusations of defaming Lungu, an offence that carries a maximum five-year prison term.

Chishimba hit the headlines in July after criticising Lungu's decision to impose emergency powers and suggesting the president should go to hospital for mental tests.