CAIRO — The chaotic scenes and defiant shouts that marked the opening of Mohammed Morsi’s trial Monday suggest that Egypt’s military-backed government may face a long struggle to bring the deposed Islamist president and his Muslim Brotherhood to heel.

Emerging from four months in captivity at a military base near Alexandria, Morsi, on trial for inciting murder, faced the judge from inside a specially constructed defendants’ cage, loudly declaring that he did not accept the legitimacy of the court proceedings. The judge adjourned the case until Jan. 8.

The ousted leader, eschewing the white prison-issued garb of his fellow defendants, wore a dark jacket and open-necked shirt instead.

“I am the legitimate president!” he shouted again and again, sometimes drowning out the judge, according to official media reports and courtroom eyewitness accounts. A wild melee broke out between Morsi’s foes and backers inside the courtroom, with rival spectators hurling shoes at each other, a grave insult in the Muslim world.

The presiding judge, Ahmed Sabry Youssef, twice called recesses when raucous chanting made it impossible to continue. Opponents of the former leader, including some Egyptian journalists who had been allowed inside with press credentials, shrieked: “Execute him! Execute him!” Morsi could face the death penalty if convicted.

Outside the heavily fortified police academy that housed the makeshift court, Morsi’s supporters gathered in a dusty no-man’s land, prevented by rolls of barbed wire and rows of police from getting too close to the compound’s outer walls. “Down with military rule!” they shouted in voices hoarse with passion. They also yelled denunciations of Gen. Abdel-Fattah el-Sissi, the army chief who brought Morsi down in a coup July 3.

Moving amid a forest of TV trucks, the ex-president’s partisans maneuvered into camera range to flash the four-fingered salute, alluding to the name of the Cairo mosque complex where hundreds of Morsi backers were killed by security forces in August, which has become a signature of the pro-Morsi protest movement.

The trial venue was moved at the eleventh hour to the police academy, whose location on Cairo’s eastern outskirts made it more difficult for demonstrators to reach. Tear gas was fired to break up larger demonstrations elsewhere in the capital, and flashpoints such as Tahrir Square were cordoned off by troops in armored personnel carriers.

The court session was not televised live, but state TV later showed scenes of the deposed president arriving and in the courtroom with the audio muted. Access to the proceedings was strictly controlled; even some lawyers, clutching letters of permission to attend, were barred from entering.