At two minutes past six last Friday morning, Nick Griffin walked to the front of the makeshift stage at the Goresbrook leisure centre in Barking, east London, and tried to make his voice heard above a braying crowd. The BNP leader had just suffered a humiliating defeat, beaten into third place by Labour MP Margaret Hodge in the constituency where he had promised to create a "political earthquake".

But as he began a flustered and angry speech, Griffin already knew that worse was to come. Rumours had been circulating round the east London count for more than an hour that the party had not only failed to get its first MP, it was on the verge of an electoral disaster in the area Griffin had once described as the party's "jewel in the crown".

"Within the next five years, the indigenous people of London will be a minority," barked Griffin, as jubilant Labour supporters taunted him with shouts of "Out, out, out!" "It is going to be too late for Barking, but it is not too late for Britain." By then, though, no one was listening.

In the next 12 hours, Griffin's worst fears were realised – and even exceeded. The party was thrashed in its two key parliamentary constituencies of Barking and Stoke Central. Its record number of council and parliamentary candidates failed to make a single breakthrough; and of the 28 BNP councillors standing for re-election, all but two were beaten.

But the Barking and Dagenham council election result was the most dramatic. The BNP had plans to take control of the authority – instead, it lost every one of its councillors there. Twelve elected in 2006. Twelve thrown out in 2010. A ruthless purge, more shocking because they didn't see it coming. Neither, for that matter, did their opponents. It was the miracle of Barking.

"This really was a disastrous result for the BNP," said Nick Lowles, who led the anti-BNP campaign Hope Not Hate. "It will have long-term consequences – particularly for Nick Griffin."

This week, those predictions are beginning to be realised, as senior BNP figures break ranks to question Griffin's leadership and, again, raise concerns about the party's finances. Griffin has been all but untouchable since he took control of the party in 1999, but now he seems increasingly isolated: mocked on far-right internet forums, forced to defend himself from the criticism of one his chief lieutenants.

"The BNP looks set to implode," says Matthew Goodwin, a specialist in far-right politics at the University of Manchester. "Griffin may hang on but, if he does, it will only be because there is no easy way to oust him and no obvious successor. He had plans to expand his reach. Now he is fighting to survive."

Walking amid the shops and bustle of central Barking this week, Zain Achtar, a 19-year-old student, could hardly stop smiling as he basked in a borough free of the BNP. "It feels like something has been lifted from the place. We can get on and go forward again."

Karena Johnson, who works in Barking's Broadway Theatre, agreed: "Having them here was an embarrassment. What happened last week means the story of Barking has changed."

Or perhaps the story of the BNP has changed. Twelve months ago, the party was celebrating its big breakthrough after winning two seats in the Euro elections. So why did that momentum stall in Barking?

The answer is a tale of determined activism by Griffin's opponents, aided by the antics of his self-harming party. That activism began to develop a sharp focus two weeks after those Euro elections, when Lowles chaired a meeting of MPs, anti-BNP campaigners, church groups and trade unionists. He gave them a detailed breakdown of the BNP's support. The message was stark.

"A decision was made to draw a line in the sand," says one Labour party figure who was at the meeting. "The coming general election was going to be the defining moment. Everyone knew that if they won then, it would be almost impossible to remove them in the future."

There was never a single anti-BNP campaign in Barking. There were meetings, events, leafleting initiatives run by Hope Not Hate – which coordinated much of the activity – and also by Labour and Unite Against Fascism. Hope Not Hate set up a base in derelict premises, and volunteers travelled across the country to prepare it for the coming battle; putting up a new ceiling, plumbing in toilets and setting up a print room. Some slept on the floors.

"The response was truly overwhelming," says Lowles. "On one day of action, we had 541 people; on another, 385; and even on election day itself, 176 people came out to help get the vote out." Many of the volunteers had not been involved in political activity before. "We had teenagers travelling up from Kent, old ladies from the other side of London turning out. It felt like a liberating experience for people who felt like we were doing something politically important."

The Hope Not Hate campaign was supported by Joe Rospars, chief digital strategist for Barack Obama from 2007 until his inauguration, and his company Blue State Digital.

Rospars said it was the "best example" of a British organisation applying the lessons of the US presidential elections. "We are seeing a genuine community-based organisation, with people coming together around a common purpose," he said.

Campaigners were able to identify the key groups least likely to vote for the BNP – women, pensioners and people from ethnic minorities. They built up an online volunteer force of 140,000 people, and Rospars advised on how to use them for maximum impact. In the month before election day, Lowles says more than 1,000 volunteers descended on Barking, delivering 350,000 specially tailored leaflets and newsletters.

At the same time, the Dagenham MP John Cruddas, and his neighbour who seemed most under threat, Barking MP Margaret Hodge, were fighting a parallel ground war against the BNP. Hodge escalated the effort she had begun some four years earlier to reconnect with voters Labour had lost to the BNP. Their rise in Barking had seen the then culture secretary heavily criticised by many inside her own party. For her, this election result represents a triumph for decency, and personal redemption.

"When Griffin announced in September that he would stand, that gave me a real scare," Hodge says. "My husband had not long died, and I was still in grief. It was a tough period. I was quietly confident that I would win, but I really wanted to smash him. And I was really concerned about the prospects for the council."

Hodge, with the help of volunteers from Unite Against Fascism, turned to the politics of shoe leather, knocking on doors and listening to people's concerns. "'What do you want to talk about?' I would ask. It was up to them."

Most talked about street cleaning, wheelie bins and antisocial behaviour, but inevitably many raised the BNP trump card of immigration. Even black residents raised the issue with Hodge. "I would say to them: 'I can't turn the clock back, but this is why the borough has changed, and we must make it work for all of us.' Some people hated that. Some would understand. But they came to feel I was listening."

The more so, perhaps, because the BNP was itself struggling to cope under a harsher spotlight. Griffin's Question Time appearance last October, with its gurning and yammering, shocked his supporters within the BNP and appeared to weaken his authority. The decision by the Equalities Commission to challenge the party's racist membership rules occupied too much of his attention, and drained the party's meagre resources. Indiscipline, heightened by personal rivalries, created a string of difficulties for the party and its leader.

At the beginning of the campaign, the BNP's publicity director Mark Collett – once a firm ally of Griffin – was arrested on suspicion of threatening to kill him. In Stoke, Alby Walker, a senior BNP councillor, said he would stand as an independent because of a "vein of Holocaust-denying" within the party. Then, a few days before the election, the party's website was closed. It was replaced with a posting from Simon Bennett, the website manager, who accused Griffin and James Dowson, the BNP election fundraiser, of being "pathetic, desperate and incompetent".

But the incident that might have had most impact on the voters of Barking concerned Bob Bailey, the BNP's London organiser and one of Griffin's closest confidants. On the eve of the election, Bailey was caught on camera throwing punches and kicks at a group of teenagers. Earlier this week, he was arrested and bailed on suspicion of assaulting two men (an 18-year-old man and a 19-year-old man have also been arrested and bailed, on suspicion of assault and affray).

"That caught the attention of voters," says Hodge. "One of the fears many people had was that a BNP win would result in violence on the street. That seemed to confirm it."

It is impossible to say how much of the Barking miracle can be explained by the efforts of the forces ranged against the BNP, and how much of the wound was self-inflicted, but after a shaky start at the Goresbrook leisure centre – before postal votes confirmed the landslide – the outcome was certainly decisive. Each confirmed result elicited whoops and backslapping, and by the end of the purge, only Richard Barnbrook, one of Griffin's senior lieutenants and himself a casualty of the wipeout, remained. He smiled a smile that at first seemed defiant, but eventually gave the impression that he was feeling queasy.

Around Barnbrook, officials – joyous at having the stain on the authority so ruthlessly removed – were quick to share the good news with friends and loved ones. One texted as each far-righter was shown the door. The last text read: "Bye bye, Nazis."

A widely shared thought is that the BNP was overwhelmed by the sort of grassroots activism that must now become a template if there is to be resurgence for the Labour party. In fact, Tony Travers, of the London School of Economics, says it was all about Labour.

"It would appear that the vote for the BNP in 2006 was some kind of political cry of anguish, based on the perception that the Labour party simply didn't understand the concerns of that part of the electorate. The fact that the BNP has been dropped in 2010 heavily suggests this section of the electorate now believes it has got the attention of the Labour party." Back in 2006, the morality of supporting an intrinsically racist party wasn't an issue, says Travers. "The voters simply used the most shocking mechanism they could to get Labour's attention."

But there is good and bad in that conclusion. Good because it suggests people in Barking voted BNP for reasons other than racism and antisemitism. Bad because if it was all a means to an end, did no one consider the impact on community relations of voting for the far right?

In any event, Dan Hodges, a strategist and spokesman for Hope Not Hate, says the safest conclusion to draw is that wider society should never again be so complacent. "We were lucky this time. People realised the threat just in time, we mobilised just in time. But we may not be so lucky next."

What is the future for the BNP now? Griffin doesn't know. He can point to the fact that the BNP won more than half a million votes, but his mood is changeable. Yesterday he sent another email, brimming with anger. "The old east London is dead," he wrote.

His party is at a crossroads. A Tory-led administration may worsen social divisions, providing the far right with new opportunities. But it might also clamp down on immigration, rendering the BNP irrelevant. Even if opportunities come his way, Griffin's party has so many problems that he may not be able to take advantage. The BNP is not dead, but it took a mortal blow in Barking. It will be hard-pushed to find its feet again.