Media playback is unsupported on your device Media caption Watch Paul Mason's Newsnight film from Morocco in full

In the age of Bogart and Bacall, the Moroccan port of Tangier was deemed "international territory". It was a backdrop to intrigue and a centre for the rootless and displaced.

Today, this city, just eight miles (almost 13km) from the maritime border with Spain, is again a transit route for those seeking refuge or a better life.

Morocco has become one the main routes for migrants fleeing sub-Saharan Africa - and for some it is deadly.

The European Union is paying the Moroccan government millions of euros to police our borders. But non-government organisations (NGOs) have reported serious violations of the migrants' human rights in the process.

I have travelled to Morocco, posing as a tourist, to see how the system works.

Filming without a permit is illegal. I applied for one weeks ago, but the government consistently asked for "more time to organise it" - and I'm about to find out why.

In Tangier, you have to look hard to find the sub-Saharan Africans.

They inhabit the backstreets and the night. In a squalid, bare-brick house - among 12 African men in a single room - I met Ibrahim, from The Gambia.

He says he is a political refugee. Three months ago he did what all the men in this room have done - he got in a boat and tried to paddle to Spain.

"I paddled for three hours and I called the Spanish people to come and rescue me. But if you call them, they just call the Moroccans - and they rescue you."

What Ibrahim alleges would be a breach of international law. If, as he believes, he was in Spanish waters, he should have been processed in Spain itself.

One thousand people managed to cross illegally into Europe from Morocco in the first three months of this year. On the sea route from Tangier, they face the Spanish police and an EU agency called Frontex.

But the first line of defence is here, in Morocco itself - where the EU has poured tens of millions of euros into an operation to stop the migrants reaching European soil.

Image caption BBC Newsnight's Paul Mason spoke to migrants who claimed that they were pushed back from Spanish waters

At any one time there are up to 20,000 African migrants stuck in Morocco, and conditions for them are harsh.

Baijalo, Ibrahim's roommate from Senegal, tells me: "If we could live like we would in Europe, we would stay here. But we can't.

"Because here there is racism, despite the fact we're all Africans. The Europeans accept us. They let us work, in factories, they let us have contact with them. But here, we don't even dare to touch them."

Police presence

As you travel across the Rif mountains, you can see why the migrants don't want to stay here. This is a lawless place.

In a town world-famous for its marijuana crop, we pass through a busy market, farmers arriving with their produce on donkeys.

The police, who have been staging roadblocks every 10 miles, are invisible here.

The journey across northern Morocco takes 12 hours by road.

Their abusers are able to act with impunity in the knowledge that their victims will be treated as criminals and offered little or no protection by the Moroccan state Medecins Sans Frontieres report

My destination is the city of Oujda on the Algerian border. Along the way, I pass the two Spanish enclaves - Ceuta and Melilla - whose land borders act like magnets to those trying to get into Europe.

The heart of the city is buzzing; a lot of the Moroccans who work in Europe are back here for the holidays.

But at the edges of Oujda, near the university, you find people who have tried and failed to get into Spain.

Amadou is from Cameroon. Unwilling to show his face on screen, he takes me nervously to the middle of a small forest.

He says: "Recently we tried to scale the border fence at Melilla. They brought a helicopter - and the helicopter landed right next to us. And then they started to throw stones at us. They beat us with batons. We could not reach the fence."

The police took Amadou and 35 of his friends to Oujda - which is 75 miles (120km) away. Then they deported them to Algeria.

"When they caught us they threw us out - to the border. There is some UN territory, there's Morocco on one side. And there's Algeria," said Amadou.

This practice of deporting people without considering their individual cases, to a country where their safety is not guaranteed, is a clear breach of the 1951 Geneva Convention.

Filming panic

Moroccan and international NGOs have documented hundreds of cases of this. It is routine.

Though we were filming in wasteland, it did not take long for me to understand why Amadou was so nervous.

Within five minutes of taking out the camera, the police arrived. Local people had called them.

We had to speed away with our interviewee in the car - and he leapt out in a panic at the first junction we stopped at.

It makes sense for Europe to pay Morocco to police the border better.

Technically the EU money - from the European Commission's "enlargement and European neighbourhood policy" section - is not to deter migration but to "improve capacity" and boost human rights.

But as I travel north, to the city of Nador, I am about to find out the difference between all these fine objectives and reality.

Nador borders the Spanish territory of Melilla. I wanted to film the border.

But no Moroccan taxi driver would take me close to the fence with a camera.

I saw squads of soldiers positioned at every culvert beneath the road parallel to the fence. I saw others fan out through the vegetation. The forest has, in the past few weeks, been cleared in a military operation.

Attack

It was impossible to find migrants there now. And almost impossible to be there without attracting attention.

Later I found Josui and Mustapha - bricklayers from Dakar, Senegal. They had come via Mali, Niger and Algeria. Their story of what happened at the Melilla fence was disturbing, and again raises questions for the Spanish government.

"When I arrived at the border fence, I tried to jump over to the other side to Melilla," says Josui, who says Spanish police, the Guardia Civil, arrested him on the other side.

The other side is technically European territory. But instead of allowing the men to claim asylum, which was their intention, they handed them back to the Moroccans.

"First they beat us and they threw us out. They handed us to the Moroccans. They trapped us. And they beat us more. They injured everybody. They even shot at us. Some of my friends are in hospital in Rabat... they have broken hands, broken legs, arm injuries," he said.

Mustapha showed me his broken thumb: "Look at my hand - broken. I could not resist. They handcuffed you."

"We had our hands behind our backs," says Josui, "As soon as the Guardia arrested us. They open the gates, pushed us back. Then the Moroccans beat us anywhere - on the head - especially while we were handcuffed behind our backs."

The men, and the NGOs who help them in Oujda, refer routinely to Frontex, but a Frontex spokeswoman was keen to point out the agency has no formal presence in Melilla.

It operates in the sea near Gibraltar, and at the Spanish port of Algeciras. So if the men's claims are true, it is Spanish law enforcement that has questions to answer.

'Shocking' abuse

In a report this year, the medical charity Medecins Sans Frontieres said it had treated more than 600 migrants for injuries sustained while trying to cross the border at Melilla in 2012.

The report said: "The fact that sub-Saharan migrants are classified as 'illegal' means that the majority live with the constant fear of arrest and expulsion and the ever-present threat of violence, abuse and exploitation at the hands of security forces, [and] criminal gangs."

"Their abusers are able to act with impunity in the knowledge that their victims will be treated as criminals and offered little or no protection by the Moroccan state."

It described "shocking" levels of sexual violence against the migrants.

The irony is, the more successful the EU becomes in blocking the migrants, the more get trapped in Morocco. Ibrahim has been here three years now and, like all the migrants I met, he is determined to get to Europe.

"Some don't know how racist Europe is because they've never been there. Some have friends there who tell them, we're living good, making our life better than here and better than where we came from. We risk our lives to help our people at home. I don't want to live in Europe the rest of my life."

Thanks to Frontex, we know the precise number of people who crossed illegally to Europe last year - 72,437.

As for those who died trying, nobody is counting.

UPDATE AT 1500BST ON THURSDAY 5 SEPTEMBER 2013 - STATEMENT FROM MOROCCAN FOREIGN AFFAIRS MINISTRY:

Newsnight asked the Moroccan Ministry for Foreign Affairs for a response to its report. Minister Youssef Amrani issued a statement in which he said:

"Morocco is victim of an increased pressure of irregular migration from Sub-Saharan Africa and has become a country of destination, by default, due to the enforced joint border control between Morocco and its European neighbours.

"Morocco continues to uphold its border management and its readmissions procedures in light of the struggle against irregular migration, all the while respecting the development and human rights aspects of migration."

He added that Morocco has developed a strategy to deal with all elements of this migration and that it was managing the issue in accordance with the law in a fully transparent manner.

"Morocco is a democratic country that has no taboo on the issue of Human rights, and has met all international requirements on the matter, specifically with the voluntary visits of the UN Special Procedures to Morocco, as well as the European Union's recognition that Morocco is delivering on its end."

"Morocco has ratified all International Human Rights Instruments, including conventions on Minors and Migrants, and continues to uphold their implementation on a national level through our legislation," Mr Amrani's statement added."