Wrapping my Touareg scarf around my face to shield my eyes from the sand and dirt, I climbed the ladder, hoisted myself onto the lip of the freight wagon and surveyed the scene. An endless line of wagons stretched out to the horizon, rocking and swaying. To either side, a landscape of boundless sandy plains and low dunes was sliding past, pin-sharp in the limpid light of the Sahara. Figures sat atop the wagons ahead, facing into the wind, yelling to each other in Arabic above the deafening noise.

One might imagine travelling through the Sahara by train to be a zen-like voyage. In some ways it is – but it is also an unforgiving and ceaseless assault on the body and senses. The booming and grinding; the constant tremors rippling through the body; the grit swirling through your hair in the hot breeze; the desert sun pricking your eyelids.

Opened in 1963, Mauritania’s Train du Desert operates a daily service from the port at Nouadhibou on the Atlantic coast to the iron ore mines in Zouerat in the country’s north-west. The full journey, which runs along the border of the disputed territory of Western Sahara, takes around 20 hours and covers a total distance of 704km. More than 2km long, the train is made up of three or four diesel locomotives, one passenger carriage and between 200 and 210 freight cars. When loaded on the westward journey to Nouadhibou, each car can carry up to 84 tons of iron ore.

The train also carries passengers to and from distant desert communities, cutting up to 500km off the inconvenient journey by road, which involves a lengthy detour south to Nouakchott, Mauritania’s capital. Many Mauritanians choose – like my companion Mike and I had done – to forgo the overcrowded passenger carriage and ride “second-class” in the freight cars, free of charge. It is a noisy, dirty and dangerous journey: falls are common, and the temperature can reach well over 40C during the day.

Hardly strangers to discomfort, Mike and I had endured sweaty trains, rickety bunkhouses and hikes through mosquito-infested swamps in subarctic Russia. But this steel desert caravan was a new lesson in austerity – an empty, open-topped metal box, completely exposed to a constant elemental symphony of heat, wind and noise.

“It’s one of the longest trains in the world,” my father would tell us at the dinner table. “Imagine travelling hundreds of miles into the Sahara desert in a cargo wagon, then getting off before dawn in the middle of the desert, praying you’ve got the right stop. Then, just as the sun’s coming up, a jeep comes over the brow of the hill.”

As a child, I was fascinated by the story of my parents’ journey on the iron ore train, a mysterious adventure that seemed incompatible with the world I knew. In 1971, they had sailed from the Canary Islands to a port in what is now Western Sahara, then travelled south down the coast into Mauritania. Somewhere along the way they heard it was possible to catch a freight train into the country’s austere interior, to settlements that were once stops on ancient Saharan trade routes. They disembarked roughly 400km inland at Choum, where a dirt road leads to the market town of Atar and the medieval holy city of Chinguetti.

The only visual record of their experience was a single Kodak slide, a relic of a pre-digital age in which every frame counted: figures in a sun-drenched freight car, peering over the rim into a sandy infinity. I never forgot that image, and often dreamt of riding the iron ore train myself one day.

Decades later, I was sitting atop a steel wagon, rolling into the Sahara. Mike and I would attempt to retrace my parents’ journey by disembarking at Choum then going on to Atar and Chinguetti. For me this was to be a kind of homage to the spirit of my parents; the realisation of a childhood dream; the closing of a circle.

In Nouadhibou, a fortunate encounter prepared us for the realities of life aboard the train. Aiba, our hotel receptionist, turned out to be invaluable. His dark eyes brightened when we told him of our plans. “Ah, the train! I’ve travelled on it so many times,” he exclaimed. “My father works in the mines at Zouerat.”

Aiba gave us plastic bags and tape to cocoon our backpacks from the dirt and dust that would be swirling around us. Then he drove us to the station and ensured we boarded the wagon that would stop closest to our station. Given the length of the train and the tiny scale of the settlements where it stops, a traveller could end up walking more than a kilometre to reach the station on arrival if they choose their wagon unwisely.

There was an odd contradiction in passing through the vast spaces of the Sahara inside a windowless steel box just 8m by 4m. So whenever the wagon began to seem too claustrophobic, we would haul ourselves up the ladders in the corners and spend a while perched on the rim in our robes, watching the dunes and scrub scroll by.

Late in the afternoon, the train began to lose speed. The blinding oblong of sky above us had weakened in intensity as the winter sun slipped lower, and most of our wagon was now in shadow. Eventually the train came to a halt in the middle of a lonely plain, stretched out in a wide curve hundreds of wagons long.

People climbed down and began to congregate at the rear of the train, exchanging handshakes and greetings. Others hung back on the peripheries or watched silently from the windows of the dirt-streaked passenger carriage, an old European-built model with the inscription “Le Train du Desert” unfurling across it. It was a convivial scene that seemed oddly out of place, as if they were chatting in a theatre foyer during an intermission rather than travelling through the desert on a cargo train.

Imagine travelling hundreds of miles into the Sahara desert in a cargo wagon, then getting off before dawn in the middle of the desert, praying you’ve got the right stop

Among them were the traders occupying the wagons ahead of us; black Africans and Arabs alike, lean young men in leather jackets and sportswear. We had seen them at Nouadhibou, hauling overstuffed bags onto the train. Then there were older men, presumably Bidan Moors from the country’s upper caste, standing aloof in their billowing white and azure boubou robes, their heads swaddled in Touareg headscarves.

The motley composition of the group reflected the complex ethnic realities of Mauritania, a country that sits at the fault line between the Arab and Sub-Saharan worlds and truly belongs to neither. Life in this nation, which only outlawed slavery in 1981, continues to be governed by a strict caste system in which there is little social contact between the paler Bidan elite and the Haratin underclass, largely composed of Mauritanians of Berber and African descent.

As I mingled with fellow passengers, the train’s role as an overland link between Nouadhibou and the remote desert communities of central Mauritania became ever clearer. Abdurahman, a young man with striking Moorish features and an intense gaze, informed me solemnly that he and his friends were travelling to Zouerat to look for work. An older man named Mohammed was on his way to visit his son in Atar, as he did several times a year.

As the sun sank, some walked out into the desert to pray, while others sprawled on the soft sand. Eventually a blast of the horn from the locomotive signalled that it was time to move on, and the passengers hastily sought the safety of the train, like sailors returning to their vessel.

Later, as darkness enveloped the landscape and the air grew chilly, the train’s human cargo hunkered down in their wagons. Soon the sky above us was glittering with stars. Mike laid out a blanket in a part of the wagon that was free of dirt, then we slumped down and tried to sleep, wrapped in Berber robes. Later, shivering in the cold, we understood why this area was clear of dust – not only was it the cleanest spot, it was also the windiest. We swiftly relocated to the dirtiest corner.

In the middle of the night, tired of fruitless efforts to sleep, I sat up. The train was standing idle in the moonlight. A stillness seemed to have fallen across the world. Outside, the windows of the passenger carriage several wagons behind us were throwing an eerie halo of light into the darkened desert. In the distance, jagged black mountains rose incongruously out of the endless flat sands. I imagined my parents all those years ago, wondering anxiously if this was where they needed to disembark.

Then a whoosh, a roar and several gigantic locomotives shot by in the other direction. Wagons heaped with dark hills of iron ore thundered past, bathed eerily in the glow of our passenger carriage. I picked out three figures, crouched around a charcoal heater; then herds of goats, standing motionless on the ore. Seconds later, the wagons were gone, leaving only clouds of slowly settling dust. Our train jolted to life again.

Around 12 hours after leaving Nouadhibou, we shuddered to a halt in the frigid darkness at Choum. For a few seconds there was silence, then voices and torchlight. We peered over the lip of the wagon. Headlights were lazily swimming in the gloom below, and the sounds of urgent activity issued from the neighbouring wagons. Knowing we had only a few minutes, we hastily hauled our bags down the ladder to where an ancient Peugeot was waiting.

A wrinkled face leaned out of the window: “Atar? Atar?” We gratefully tumbled in. Beside us, the wagons began to roll again, booming past us through the dust before vanishing into the night. The driver, who seemed to have mistaken us for locals in our robes, began chattering away in Arabic, but the gentle motion of the car soon lulled me to sleep.

In a guesthouse in Chinguetti the next evening, fronds of date palms whispering above us, my head still reverberated with the roar and rattle of rolling stock. I half-recalled fumbling with documents at police checkpoints in the darkness, wandering the dust-blown streets of Atar at dawn, stealing a couple of hours’ sleep on a carpet in the bare back room of a taxi garage, then bumping across a rocky wasteland in a creaking car, Mike dozing against the window.

Chinguetti was a place of fascinating dislocation, its ancient libraries and nameless streets collapsing slowly into piles of stones amid an endless sea of billowing golden dunes. Out of time, it was an elegiac picture of vanished glory, a place that was slowly forgetting itself.

And in the following days, as we languished here amid the ruins, the train that had brought us came to seem less and less real, as if the whole experience had just been the product of some feverish, chaotic dream, or perhaps an imaginary memory whose details were already beginning to blur imperceptibly with those of my parents’ journey all those years ago. But for almost a week, specks of iron ore dust continued to trickle from my ears.