A court in Nigeria's economic capital Lagos on Thursday ordered the military to halt forced evictions of coastal communities after thousands of people were removed from their homes.
Navy personnel last week shot in the air and bulldozed houses as they cleared a community of some 10 000 people living on an island in the bustling megacity.
The military said the operation was aimed at stopping the looting of nearby oil pipelines but residents complained they were being punished for the crimes of a small minority and given no notice of the eviction.
Dozens of men, women and children from the Tarkwa Bay and Okun Ayo communities crowded the courtroom on Thursday as they launched their bid to end the clearances.
The judge issued an interim injunction ordering the authorities to stop the demolitions of homes, businesses and community facilities or evicting any more inhabitants.
It forbade the military and government from harassing people from the community "with shooting of guns, other violent attacks, threats of arrest or arrest".
The displaced residents celebrated the ruling and some pledged to return to their communities.
"That is a huge victory for us, that we are going back to our community. We are very happy, because our students, our children, will be going back to school," one resident Solomon told AFP.
"The government should try and give us back our homes that they demolished. We cannot afford to build another home."
The interim injunction remains in force until a new hearing when the authorities can defend themselves. Activists said they would look to prolong the court order.
Lagos has in recent years seen repeated forcible evictions of poor communities living in prime locations, especially along the waterfront, as developers look to cash in by building high-end properties.
Tarkwa Bay and Okun Ayo were the latest of some two dozen communities in the area that had received eviction orders as part of the broader operation by the navy, activists from the Nigerian Slum/Informal Settlement Federation said.
Tens of thousands of people have left their homes in surrounding districts since December 21 and their residences have been demolished, the organisation said.
Tarkwa Bay, which is accessible only by water, is one of the rare areas left largely undeveloped despite the breakneck pace of construction in one of Africa's most populous cities.
Oil pipelines that supply Lagos run along beaches on the Atlantic coast in the area that is a popular escape for day-trippers from the city.