When they had pulled their faces off the wire fences and returned to their corrugated iron shacks, the people of this township must have thought it had all been a pleasant dream.

In a lumberjack shirt, black jeans and white trainers, David Beckham floated through their lives like a spirit sent to prepare them for Africa's first World Cup.

"Who are you?" asked a boy in training gear, inside the compound. But he meant Lord Triesman, the Football Association chairman, who has coaxed Beckham to South Africa to revive England's own faltering 2018 World Cup bid. "I was a teacher," Triesman began. It was Beckham's tuition they craved.

How to get out of the township? How to end up in a 1bn rand (£82m) boutique hotel on Cape Town's waterfront? How to be so famous that no football event can be viewed except through the David Beckham prism? These are questions that must have troubled the children of the PP school, on site B of the sprawling Khayletisha informal settlement, where, according to one estimate, unemployment runs at 80% and one in three of the 2 million residents are HIV-positive.

Beckham arrived with a heavy security detail but no fanfare. He looked subdued. His grandfather, Joseph West, died on Wednesday. And besides, he is too skilled in the art of empathy to stride into a township like a Hollywood narcissist. In these moments you see the charm that underpins his attention-seeking. "I'm comfortable sitting in a room with the officials, but this is what I love doing. I love being a part of these events and at these townships and these things that have been created for kids," he said, as an organisation called Coaching for Hope showed off the Chris Campbell memorial astroturf pitch.

Campbell was an American 21-year-old university footballer who collapsed and died after trying to run a five-minute mile. The pitch is a $320,000 memorial laid by his friends. It stages midnight leagues for local gangs and training for smaller children, some of whom have had their growth stunted by sniffing glue.

It was about the furthest point Beckham could find from Fifa gladhanding and the 2010 World Cup draw, which starts at 5pm today, UK time. In his three World Cups, Beckham has been sent off (1998), injured (2002) and held up as a symbol of the golden generation's downfall, in 2006, when he cried as he relinquished the captaincy.

The machine that is his fame has found new impetus with his ambassadorial role for the 2018 bid and the restoration of his England career under Fabio Capello. What do you need to be a great coach, like Capello, a girl asked. "Passion for the game. You need good knowledge, but passion is the bigger thing," Beckham told her.

He sat on the bright plastic pitch with Lucas Radebe, one of South Africa's most decorated players, while locals gathered outside the fence topped with barbed wire. When a group of women serenaded him Beckham walked slowly to the mesh to greet them. The figures ducked and swirled in ecstasy.

Beckham's good fortune in these circumstances is that he still radiates the air of a boy from Leytonstone who beat the system and has not let it ruin him inside.

What connected these lives: the ubiquitous sporting superstar, dropping in for a couple of hours, and the township dweller, for whom the World Cup will descend like a giant spacecraft and lift off again, one month later? Well, the game, at a push, and family, which is Beckham's leitmotif.

He spoke of his grandfather dying: "If I had decided to go home, I know what he was like – he's an East End, strong person – and I know what he would have said to me, which I can't repeat. I will be there for the funeral without a doubt. But my granddad would have shouted at me for leaving this because he was passionate about his country, he fought for his country and I know how proud he was of me. He would have wanted me to stay."

He is no position to emote about deprivation, of course, but then nor were any of us, except, perhaps, as an exercise in guilt. "It's amazing that places like this still exist in the world, but it's reality. It's something that touches many people's hearts. When I went to Sierra Leone, it was one of the first times I had actually gone into the grounds and seen the poverty like that," he said. "At first I was worried about being too emotional because I'm an emotional person anyway, but it surprised me because the strength in these people and the strength around these townships is something special.

'And it's not until you're actually there and part of it that you realise just how strong these people are. Just watching the kids play football, it's just like watching my boys play – that passion, that fun and just having a football and playing around. Kids are all the same all around the world."

He didn't mention the best bit. Assembled in a semi-circle around the visiting god, the children of Khayelitsha asked Radebe as many questions as they did Beckham. "The most important thing," their South African hero told them, "is never forget where you come from."