A sci-fi blockbuster that's also an allegory of apartheid? District 9 is only the biggest of a glut of films about South Africa's recent traumatic past

Poor aliens. They trek halfway across the galaxy, run out of gas and end up living off cat food in, of all places, 1980s Johannesburg. Then they get the kind of reception that asylum seekers who don't speak the language have come to expect. This is the improbable premise of the surprise sci-fi hit of the year. District 9 shot to the top of the US box office in its opening weekend and earned the kind of reviews that eluded George Lucas even the first time around. Its modest credentials include a 29-year-old debutant director, a budget of just $30m and a cast of unknowns.

But District 9, released in Britain next month, also boasts two points of instant recognition. Its producer is Peter Jackson, the director of The Lord of the Rings films and King Kong. Its setting is apartheid-style South Africa, a time and place that seems both close and yet distant, a paradox that film makers are now finding irresistible. Improbably, the traumas suffered as a result of South Africa's white-minority rule have now become one of cinema's most fertile territories.

The warped society apartheid created will be examined in a rugby film about Nelson Mandela, the story of photographers capturing township violence, and the startling real-life account of a black girl born to white parents. As a result, Hollywood stars – including Morgan Freeman, Matt Damon, Clint Eastwood, Ryan Phillippe, John Malkovich and Sophie Okonedo – have been crowding the arrivals halls at South Africa's airports. The gol rush comes 15 years after Africa's most powerful nation held its first democratic election, and on the eve of the biggest sporting event in its history. All eyes will be on South Africa next year when it hosts the continent's first football World Cup.

Of all the new releases, District 9 wears its politics most lightly, making no mention of apartheid or its legacy in today's impoverished black townships. But the allegorical overtones are inescapable in the plot about aliens who, their spaceship stranded above Johannesburg, have to endure a daily routine of unemployment, gangsterism and xenophobia in a squalid shantytown. The Prawns – as they are known in derogatory slang because of their vaguely crustacean appearance – spend their hopeless days brawling and getting high on pet food.

District 9's director, Neill Blomkamp, lives in Canada, but was born and grew up in Johannesburg. "In my opinion, the film doesn't exist without Jo'burg," he told journalists last month. "It's not like I had a story, and then I was trying to pick a city. It's totally the other way around. I actually think Johannesburg represents the future. What I think the world is going to become looks like Johannesburg."

District 9 has been lauded for combining an allegory of apartheid with awesome special effects, but it is perhaps the real-life locations that will linger in audience minds. Blomkamp admitted that this authenticity came at a price. He was terrified daily that his convoy of vehicles would be a target for carjackers as it travelled to work in Soweto. One night the fears were realised when his driver had a 9mm gun put to his head and his car stolen. "The people are warm, but the environment is so caustic and unbelievably disgusting to be in. Every single thing is difficult. There's broken glass everywhere, there's rusted barbed wire everywhere, the level of pollution is insane. And then in that environment, you're trying to be creative as well. But of course, that gave birth to the creativity, so it kind of goes both ways."

District 9 is not the most alluring advert for South Africa as a place for film-makers to ply their trade. But the reality is somewhat different. The country boasts superb locations, world-class studios and technical crews, and relatively low costs. It also has a compelling history that the rest of the world is starting to rediscover. As the teacher Irwin observes in Alan Bennett's The History Boys, there is no period so remote as the recent past.

None comes bigger than Invictus, an adaptation of British journalist John Carlin's book Playing the Enemy, which tells how Mandela used the rugby world cup to unite the nation. South Africa's first black president pulled off a political masterstroke by wearing a Springbok jersey to embrace the traditionally Afrikaner sport and rally both blacks and suspicious whites.

The story has been given the Hollywood treatment with Freeman as Mandela and Matt Damon as the Springboks' captain, François Pienaar. Carlin says: "Martin Luther King had his dream but in South Africa it happened in real life. It was a day when everything came emphatically right for what Mandela had worked for. He was a political genius in not only winning over his people but also the white population. This was the day he reached his peak."

After a chance meeting in America, Carlin discovered that Freeman had long nurtured an ambition to make a film about Mandela, and had tried and failed to adapt his autobiography, Long Walk to Freedom. Carlin's book came as a godsend to the 72-year-old actor. "Mandela has to be one of the great roles in Morgan Freeman's life," says Carlin, who befriended Mandela during his time as a foreign correspondent. "He knows Mandela personally and has given to his charity. He's the right age, he's tall, he has the presence and gravitas. He can convey the force of personality, the charm and the charisma. He has the Mandela air."

While Invictus, due for release early next year, will doubtless end on a high note, some feel that Mandela's legacy has been squandered by his successors. The African National Congress mastered the poetry of liberation, it is said, but has proved less eloquent in the prose of governing. Carlin, however, remains mostly upbeat. "For all the internal rumblings, South Africa is still a politically stable country. This year's election was generally held to be free and fair. I still think it's amazing after 15 years. When I interviewed Desmond Tutu he said that when you see black and white kids playing together in schools, it lifts your heart. But we could have done it all so much better. It was a colossal misfortune that Thabo Mbeki was Mandela's successor."

Freeman, though, is only the most high-profile actor who is immortalising Mandela on screen. British actor David Harewood plays the emancipation lodestar in Mrs Mandela, an upcoming BBC biopic of Winnie Mandela shot in and around Soweto. Harewood says: "We had white members of the cast and crew who said they knew nothing about this story. Maybe these films can tell South Africans something about their own history."

Mrs Mandela's title role is taken by Sophie Okonedo, who has already been seen this year in Skin, playing Sandra Laing in one of apartheid's most haunting stories. Laing was a black child born in the 1950s to a white Afrikaner couple . They raised her as a "white" girl but she was ostracised at school, reclassified as "coloured" and expelled. Her father fought for years in court and finally had the classification reversed, but was heartbroken when Laing eloped with a black man. Now in her 50s, Laing owns her own home and has received substantial money from the film-makers, but she is still estranged from her brothers.

Why return to this story now? Anthony Fabian, director of Skin, says: "Many people tried to dissuade me from making the film because they said apartheid's over. But don't forget there's a whole generation of kids who've grown up since apartheid. They need to know about it, in the same way that there was a spate of Holocaust films to remind people that this must never happen again.

Fabian says he did not set out to make Skin overtly political. "It is about identity and what it means to be one race or another. It's resonating in America especially, where the question of whether you're black or white has been topical in the presidential election. This suggests to me it's a universal human story about belonging: where do I come from, who do I belong to?"

The outside world is looking in, but it could take somewhat longer for South Africa to develop a booming homegrown film industry. The domestic hit of the year, White Wedding, was shot in 19 days on a budget of £450,000. Disgrace, an adaptation of JM Coetzee's Booker prize-winning exploration of post-apartheid mores, was made by Australians because no South African financing could be raised.

But some local pride may be restored with The Bang Bang Club, based on a book by the photojournalists Greg Marinovich and João Silva, which recreates the fragility of the "Rainbow Nation" in the early 1990s in townships such as Thokoza, where supporters of the ANC and Inkatha Freedom Party fought running battles. The Bang Bang Club was a magazine headline that stuck, and referred to a group of photographers who braved the carnage to show the world what was happening. Nine days before the first democratic election one of them, Ken Oosterbroek, was shot dead and Marinovich wounded. Another "member", 33-year-old Kevin Carter, killed himself two months after winning a Pulitzer prize, leaving a note which said: "I am haunted by the vivid memories of killings and corpses and anger and pain ... of starving or wounded children, of trigger-happy madmen, often police, of killer executioners. I have gone to join Ken, if I am that lucky."

Marinovich, who is played by Ryan Phillippe in the film, says he found it painful to return to the street where his friend was killed. "It was all filmed in the exact same locations, including the shooting of Ken," he says. "It was very difficult to watch. The worst six years of my life were condensed into six weeks. It was traumatic for me and for people who live there. They got angry and upset and tried to stop us filming. Many of their issues are still unresolved."

But Marinovich, now 46, believes the film will bring the neglected story of apartheid's violent dog days to a wider audience. "We're getting some maturity and it's not just white voices telling these stories. We're getting a different perspective on our recent history." He sums up the ambivalence of many who oscillate between seeing modern South Africa as a glass half-empty or a glass half-full. "What did you think of the future in 1992 and what did you think in 1994? In 1992, it was disaster with no hope. In 1994, it was brilliant and nothing could go wrong.

"The years since have tempered both of those. South Africa is not everything we would have hoped for, that's for sure. But compared to some of the apocalyptic visions, it's great."