DAKAR, Sept 2 (Reuters) - Papa Demba Sow left Senegal two years ago hoping to make a better life in the oil-rich central African country of Gabon but in July he was arrested by police, thrown in jail for a month and deported along with hundreds of other Africans.

The plight of African migrants struggling to reach Europe, alongside thousands fleeing violence in the Middle East, has stirred international alarm this year, with hundreds dying at sea on the perilous Mediterranean crossing.

But the majority of Africans who emigrate remain within Africa.

Yet, amid rising concerns over the spread of Islamist militant groups on the continent and several economies hit by a slump in commodities prices, some African nations are clamping down on those migration flows.

Gabon, whose oil reserves have given its 1.5 million people amongst the highest per-capita income in Africa, has long been a magnet for migrants from countries like Senegal, an arid West African state with a tradition of emigration dating back decades.

Sow, a 33-year-old welder, went to Gabon to join family members already living there but said it had become extremely hard to obtain residency. Police officers harassed African immigrants on the streets of the coastal capital Libreville until they were paid off, he said.

In detention, more than 300 migrants were packed into a few rooms, with many forced to sleep on the floor. Breakfast was a slice of bread, with a plate of rice and fish for dinner.

“They treated us really bad, like dogs or sheep,” said Sow.

It is becoming a familiar story as many African countries seek to close their doors to mass migration, removing a pressure gauge for poverty and unemployment within the region.

With European Union and African heads of state due to meet in Malta in November to discuss the Mediterranean migration crisis, experts say any solution needs to address the lack of economic possibilities in sub-Saharan Africa.

“The situation is changing. Some African countries are becoming less flexible in accepting migrants,” said Michele Bombassei, the International Migration Organization’s (IOM) Migrant Assistance Specialist for West Africa.

“What’s happening right now in the Mediterranean is just the last step of a long, long process that, in many cases started here, in West Africa.”

‘SCARED FOR THEIR NATIONS’

The IOM does not have overall figures for migrant expulsions in Africa. Yet the small, oil-rich nations of the Gulf of Guinea - traditionally a destination for migrants from across West and Central Africa - have clamped down hard.

Amnesty International has documented thousands of deportations by Republic of Congo. The foreigners, many of them from neighbouring Democratic Republic of Congo, were often simply put on pirogues and shipped across the Congo river to Kinshasa.

Nearby oil-rich Equatorial Guinea deported hundreds of people in the wake of the African Nations Cup football tournament this year.

Even in South Africa, the continent’s most developed economy, many economic migrants fled an outbreak of xenophobic attacks this year by residents afraid foreigners are taking their jobs. At least seven people were killed.

North African oil producer Algeria has deported more than 3,700 migrants to Niger this year, mostly women and children who came to beg on the streets, as part of a bilateral agreement between Algiers and Niamey intended to curb illegal immigration.

Cameroon, Niger and Chad have also deported thousands of people in the face of terrorist attacks within their borders by Nigerian Islamist group Boko Haram.

Sory Kaba, who heads the Ministry of Foreign Affairs’ department for Senegalese abroad, said the rise of militant groups such as Boko Haram had fed xenophobia and deportations.

“They are scared for their own nations,” said Kaba. “That’s why they make it more difficult to enter and they make it more difficult to stay.”

‘POLICIES ARE WATCHING US’

In Republic of Congo, Abdoulaye Ehiaw, the president of the Association of Senegalese Youth, has lived in the country for six years. He said the expulsions of migrants had slowed in recent months.

“It’s better but in any case, Congo’s domestic politics are still focused on us,” said Ehiaw.

An Amnesty report in May said the security operation, dubbed “Mbata ya Bakolo” or “slap of the elders” in Lingala, was ostensibly meant to target criminals but became an excuse for mass expulsions. Amnesty said police destroyed property, extorted money and raped women and girls.

A second phase of the operation was launched in May, targeting West Africans in Pointe-Noire, Congo’s oil hub and second-largest city. Police said that month they had arrested 1,150 people, primarily from West Africa and Democratic Republic of Congo.

“We’re certainly concerned to see the same kind of attitudes (in Africa) that we have seen around the world and in Europe — where whole societies see migrants or refugees as ‘others’, as people who are not deserving humane treatment,” he said.

Mamadou Ka, a shopkeeper in Gabon who had been deported to Senegal, agreed. “We are all Africans...It is necessary to have a policy of integration, of free circulation.” (Editing by Daniel Flynn and Anna Willard)