Four travellers sit by torchlight in a bare room with thin, tatty mattresses slung around the edge: two Mauritanian men, a Frenchwoman and myself. In another corner, some children half-sing, half-chant their Arabic homework. Three of us are playing Scrabble in French; one of the Moors (as they're known) is winning hands-down, while his countryman brews sweet green tea. We're random acquaintances, thrown together by bush-taxi chance, and we're waiting for a train. It's running late – five hours late; but we don't mind. This isn't any old train. It's the longest in the world.
I'm on Mauritania's northern frontier, in the town of Choum, whose only claim to fame is its railway station. It feels like a Western film set: wooden shacks, decrepit vehicles and ragged children cluster alongside a railway track that stretches into the desert with the Adrar escarpment behind, pink-tinged in the setting sun. It's the only stop between the iron-ore mines of Zouérat and the refinery. Our train comprises 2km of iron-ore wagons that carry 20,000 tons per train to the coast, with just a couple of passenger carriages tacked on.
We finish our game of Scrabble, then pool our resources for dinner: bread and sardines, biscuits, squashed bananas and the ubiquitous frothy green tea. At last it's time to trudge to the appointed spot, somewhere out in the darkness. There's a faint glow on the horizon, a distant hum in the air. We wait with a group of fellow passengers, hugging ourselves against the chill desert wind.
Over the course of an hour, the hum becomes a throb, and the glow a single light. The engine roars past, followed by wagon after wagon; slowly, they shudder to a halt, and everyone begins to run. We've got a few minutes to get on before the driver pulls away.
The two grubby carriages are unlit, with narrow doors nearly a metre off the ground. They are jammed half-shut. Bekhayr, one of my Mauritanian friends, scrambles up. A woman ahead of me virtually throws him her year-old son. "Pass me your bag!" he yells, but an obstacle has appeared: a toothless, indignant old man, shouting in Hassaniya Arabic. "Nasrani," I manage to catch, followed by "billet, billet," and I get the drift: "The foreigners can't get on without a ticket!"
Wild protestations ensue from everyone. He's trying it on – tickets are sold on the train – but time's running out.
Someone distracts him and I hurl my rucksack in Bekhayr's direction. "Avancez, Madame! Avancez!" comes a cry, and I try to follow my bag. I hoist myself into the doorway and feel a helpful shove. I'm on board. "Avancez!" I hear again. I can't; now I'm jammed against an enormous water butt. But the pressure's mounting, so I take the only route available: over the butt – somehow – and into the train's corridor. I survey the huddled bodies and random baggage that loom in the darkness, and figure that the next 12 hours might not be the most comfortable of my life.
"Quelle aventure!" enthuses my French friend, as we hunt for a seat.
All in all, she's just about right. This vast Western African nation, the "land of the Moors", is made up mainly of desert plateaux and dunes; but, as with its trains, it has some of the most spectacular in the world.
Back at the start of my trip, I'd joined an Explore trip going deep into the mountainous Adrar region for a four-day trek. En route, we passed the dunes of Amatlich, which rise like a sand tsunami from the plains; a nomad and his camel wandered by in a photogenic sort of way, dwarfed by the gravity-defying slopes.
We climbed the Akhdar plateau to our first camp, on the edge of a sweeping sea of sand. From here, we left the 4x4s and walked, with camel back-up, through an ever-changing landscape of white dunes, orange dunes, red dunes, rocky ground studded with acacias, desert melon fields and date-palm groves. The latter were surrounded by apparently uninhabited tichits (rounded palm-frond huts), symptoms of their owners' nomadic lifestyle: people appear in droves come July and August, when the dates are harvested.
Nights were spent under the stars; we rose at dawn, ate delicious bread baked by the camel drivers, then walked on at a leisurely pace. On our third day, we reached the edge of the plateau and gazed at an astonishing view: the Oued el Abyad, or White Valley, with its dunes that fold and unfold against the stark pinkish-black of the Adrar's rocks.
We clambered down, marched the crest of an undulating dune, and sat. Far below, in the flat, sandy valley, we watched our own little caravan of camels appear, taking the path of less resistance.
Yet however remote our lunch stops or camps, we were never alone. With an unerring nose for a tourist trail, nomads popped up everywhere, bearing little bundles of trinkets. The goods themselves were disappointing: cheap imported jewellery, little in the way of local crafts. But as my journey continued, this detail became a key piece in Mauritania's social and historical jigsaw.
We travelled to the desert towns of Chinguetti and Ouadane. Both were once seats of Islamic learning, and important links in the trans-Saharan caravan trade. Chinguetti, which was used as a stopover by pilgrims on their way to Mecca, has libraries full of ancient, beautifully transcribed Korans and the works of Islamic scholars. Now, the mosque still stands proud in the centre of the old town, which is under constant threat from the dunes that surround it. Sand drifts along the streets, piles up and is not easily shifted.
Ouadane, heavily fortified, dealt with a different kind of threat. It sits on the slopes of an escarpment, so here we climbed up the jumbled rocks of ancient winding streets, watched scampering dassies and inspected termite-nibbled palm beams.
But it is from the plain that Ouadane's former glory hit home. Gazing up at the rocky ruins, I imagined traders' camels milling under the walls, the battles with desert raiders, and the determination to protect, above all things, the fortified well.
And so to the question: who are the Moors? Amid the jumble of objects that is Ouadane's museum, I chatted to the owner, Sidi Abidine Sidi. He explained the double wave of Islamic influence on Mauritania – while the Berber Almoravids brought Islam in the 11th century, it was the Beni Hassan who brought Arabic, six centuries later. In doing so, ethnic lines were blurred. Berbers and Arabs became the "white Moors", while indigenous black Africans became the "black Moors", their slaves. Hassaniya Arabic became both groups' mother tongue. Now, Wolofs, Fulani and Soninke from the south (black Africans who were never enslaved) form a substantial portion of the population, but the line between black and white Moors remains deeply entrenched; slavery was officially abolished only in 1981.
Does it persist, I asked Sidi. He replied that it does, but as what he calls l'esclavage volontaire. Employment prospects are such that people choose to remain where they are; and what can you do about that? It seems that it's a case of better the devil you know – but recent reports from Amnesty International suggest that as many as 90,000 may still be owned against their will.
Later, I saw more of the structures that underpin society; it's a kind of caste system, in which warriors and marabouts (broadly speaking, scholars) sit on top. Of course, there are other groupings, too. I met a white Moor from a warrior family, who explained those disappointing bundles in the desert. "I couldn't make jewellery even if I wanted to," he told me. "Only artisans can do that."
A land of age-old customs, then – not all of them palatable. But others have greater appeal. There's the endearing click at the top of the mouth, to indicate consent or agreement. There's the way the men pee crouching down. And there's the unstinting hospitality, and not a little chivalry. I was invited to eat in a number of family homes, sampling couscous and goat with white Moors, and the Wolof speciality ceebu jen (a trayful of rice, fish and slow-cooked veg) on the coast. And then, on my last morning, I found myself on the streets of Nouakchott in search of a taxi. They were mostly unmarked. A car pulled up and I explained that I needed the Garage Rosso, but had no idea where it was. The driver didn't know either, but he seemed confident he would find it.
"How much?" I asked him.
"Oh," he said. "I'm not a taxi. I just saw you with all your bags and thought I should give you a hand..."
And he did.
The writer travelled with Explore (0844 499 0901; www.explore.co.uk), which has since suspended its two-week Mauritania trip. But it still offers Timbuktu & Dogon Trails in Mali, which starts at £1,769 per person including flights, transfers, B&B accommodation and guide.
You can fly to Mauritania via Paris with Air France (0870 142 4343; www.airfrance.co.uk); via Casablanca with Royal Air Maroc (020-7307 5800; www.royalairmaroc.com); or via Algiers with British Airways/Air Algerie (0844 493 0787; www.ba.com).
Independent travel is by bush taxis, which set off when full. Tailored desert trips can be organised by Allal Amatlich (00 222 540 0154; email: firstname.lastname@example.org), based in Atar.
Auberge du Maure Bleu, Chinguetti (00 222 546 4718; www.maurebleu.com). Doubles start at €36 (£30), including breakfast.
Red tape & more details
Britons require a visa to visit Mauritania. These can be obtained from the Mauritanian Consulate General, 89 rue de Cherche-Midi, 75006 Paris (00 33 1 45 48 23 88) and cost €30 (£25).
The Foreign & Commonwealth Office says: "There is a high threat from terrorism. We advise against all but essential travel near Mauritania's border with Algeria, and near Mauritania's northern border with Mali, because of the risk of banditry, and the activities of smugglers and extremist groups."