Protests erupted late Thursday in Peru's southern city of Ayacucho, with clashes between demonstrators and the military killing at least seven people as unrest grows over the treatment of ousted president Pedro Castillo.

The country's Supreme Court earlier on Thursday ordered Castillo to remain in detention for 18 months after his arrest last week, which has sparked protests that have killed at least 15 people across the South American nation, according to authorities.

Castillo was removed from office and detained after he tried to dissolve the legislature and announced he would rule by decree, in what opponents say was a bid to dodge an impeachment vote amid several corruption probes.

The leftist former schoolteacher stands accused of rebellion and conspiracy and could be jailed for up to 10 years if found guilty, according to public prosecutor Alcides Diaz.

A Supreme Court judge granted the request from prosecutors to keep Castillo in custody, saying he posed a flight risk after trying to seek asylum at the Mexican embassy in Lima. The detention order extends to June 2024.

His removal from office has sparked protests across the country with thousands taking to the streets every day, including in the capital Lima on Thursday, despite a state of emergency decree that allows the military to participate in law enforcement operations.

Clashes between the military and Castillo's supporters left at least seven dead on Thursday in the southern city of Ayacucho, regional health authorities said, with fighting near the airport killing two, according to the country's ombudsman.

The ombudsman put the number of injured at 340, with the police saying at least half of that total are from their ranks.

Castillo's supporters -- dozens of whom have camped outside the prison where he is being held in the capital -- remain undeterred and unbowed.

"I am in total disagreement with the Peruvian justice system, because everything is for sale," demonstrator Rolando Arana, 38, said in Lima after the court ruling on keeping Castillo detained.

"The president has been kidnapped. There is no other word for it," 41-year-old Lucy Carranza said earlier.

On Thursday, 300 people marched near the prison shouting "Freedom for Castillo" under the watchful eye of police.

Dina Boluarte, the former vice president who was quickly sworn in as president after Castillo's arrest, on Wednesday declared a nationwide state of emergency for 30 days.

The following day she exhorted Congress to approve a constitutional reform that will allow her to bring forward elections slated for July 2026 to December 2023.

New elections are one of the main demands of pro-Castillo demonstrators, which have included Indigenous people from Peru's Amazon regions in the center and southeast.

'They didn't let him govern' 

Four airports have been shut down due to the protests, while more than 100 roads throughout the country remain blocked.

Hundreds of tourists have been left stranded at Peru's most popular attraction, the 15th-century Inca citadel Machu Picchu, after train service to the site was suspended.

Protest leaders have said they will stage new demonstrations again on Friday, demanding Castillo's release, Boluarte's resignation, Congress's closure and new elections.

Castillo and his attorneys were not present at the virtual hearing that determined he should not be released.

The judge said Castillo had refused to accept the summons, so his case was assigned to a public defense lawyer.

The hearing was supposed to take place on Wednesday when Castillo's initial seven-day detention expired but was postponed by 24 hours after the former leader's lawyers argued they had not received the necessary documents related to his case from prosecutors.

Castillo has called his arrest unjust and arbitrary, while urging security forces to "stop killing" protesters.

Speaking outside the prison where Castillo is being held, his niece Vilma Vasquez accused his political opponents of mounting a smear campaign against the ex-president even before he took office last year.

"From the first day that he took office and even during the (election) campaign, already we were (called) terrorists," said Vasquez.

"They didn't let him govern -- we were thieves, we were corrupt. We're going to stay here until he leaves" prison.

Before his election, Castillo's detractors tried to paint him as a dangerous communist and sympathizer with Shining Path rebels who sowed chaos in the 1980s and 1990s. Castillo says he fought against the Maoist guerrillas.

He was in power for only 17 months in Peru, which is prone to political instability and is now on its sixth president in six years.

His short period in office was marked by a power struggle with the opposition-dominated Congress, and six investigations into him and his family mainly for corruption.