A Somali court has ordered the deportation of 27 Kenyans found to be in the country illegally.
This is the first time in 25 years that Somalia is to expel foreigners for overstaying their visas.
The men have also been fined $10 (£6.50) for each day they were in the country illegally.
The BBC's Mohammud Ali says job opportunities for foreigners have opened up as peace has gradually returned to Somalia.
Judge Hashi Elmi Noor said that the case was a warning to others who are found to be in the country illegally.
It is not clear how long the deportees had stayed in Somalia.
Our correspondent says that a growing number of foreigners are taking up jobs in the construction and hotel industries, while others are getting teaching jobs in colleges and schools.
According to a recent Somali law, work permits are now mandatory for all foreigners and employers are urged to give first priority to Somali nationals.
The government is trying to create job opportunities for young people but the damage to the education system caused by the civil war has left many without crucial skills.
Years of anarchy in Somalia followed the downfall of President Mohammed Siad Barre in 1991 and more than a million Somalis fled the country as a result, with nearly half a million ending up in Kenya.
The current government, backed by the African Union, is slowly gaining control of Somalia as it battles with the Islamist militant group al-Shabab.
For its part, the Kenyan government has accused some Somali refugees of links to al-Shabab, which has staged several attacks in Kenya.
About 400 Somalis were rounded up and sent to Mogadishu from the Nairobi district of Eastleigh, which is home to many ethnic Somalis.
It also threatened to start mass deportations from the refugee camps but later drew back under intense pressure.
Kenya has also started building a barrier along its long border with Somalia but progress has been slow so far.