LONDON – Populist winds ripped through Western politics in 2016, ejecting comfortable elites and upsetting the assumed world order.

Looking back at events like the vote to take Britain out of the European Union, some observers join the dots and claim they were inevitable. But for those who sought to drive these changes, victory was far from certain.

Behind the scenes, the Brexit campaign teetered on the brink of collapse, beset by infighting and starved of political leadership until the final few months. We succeeded only by rejecting many of the orthodoxies of political campaigning — often more out of necessity than choice — and pursued a strategy that football commentators would describe as “hitting opponents on the counter attack.”

Here is how we did it.

Scuffing up the pitch

Tory political strategists have long described the run up to campaigns as “rolling the pitch,” preparing voters for the forthcoming arguments so they are received as favorably as possible, much as groundsmen use rolling machines ahead of cricket matches to make sure the wicket is in the best possible condition.

But years before the campaign started, then Prime Minister David Cameron did just the opposite; he made his case more difficult.

Back in January 2013, I was travelling back to London from a football game, as Cameron set out his plan for “fundamental” reform of Britain’s relationship with the EU after which he would hold a referendum on the country’s membership in the bloc.

I remember shouting at the car radio as I was driven home by Nick Timothy, now Theresa May’s co-chief of staff. I thought it was a stupid idea, a terrible solution to a short-term political problem that would give the United Kingdom Independence Party (UKIP) a huge amount of oxygen. Cameron could easily lose.

Indeed, the landscape meant he’d be facing an uphill battle. By the time of the 2015 general elections, immigration had become synonymous with the EU in the public psyche. Focus groups reflected voters’ expectations the prime minister would be able to negotiate reforms to free movement within the EU.

Soon after Cameron’s unexpected triumph, I sat with a group of bank lobbyists as one of the prime minister’s aides set out the parameters of the deal the U.K. would be asking for. The gap between what the public expected and what Cameron was requesting was striking.

I had been a Euroskeptic my whole adult life but I’d backed EU reform, not leaving altogether. The level of ambition for this once-in-a-generation renegotiation seemed so limited and I decided I was out.

As Ryan Coetzee, director of strategy for Stronger In, put it, Cameron’s renegotiation was as an exercise in “scuffing up” the pitch rather than rolling it.

Worse still, in a bid to get the whole referendum over and done with as quickly as possible, the government’s message changed within a matter of weeks. Cameron went from claiming that the EU needed major changes to saying that if we left the bloc, World War Three would break out, house prices would plummet and millions of people would lose their jobs.

Cameron was the most persuasive politician of his generation by far, but now his reputation for being straight on the EU was tarnished.

It could have been very different. Instead of promising major reforms he had no means of delivering, Cameron should have simply announced that if he was reelected as prime minister he would hold a straight In-Out referendum, and that he would campaign for Britain to stay in.

Instead of using up huge amounts of energy and political capital trashing the EU’s brand, he could have crafted a multi-year campaign about the benefits the bloc brought to the U.K.

Limits of unity

Meanwhile, as Cameron haggled with the rest of Europe, Euroskeptic factions at home fought for control of the campaign.

There were real differences in approach between the Conservative campaign to Vote Leave and Nigel Farage, the leader of UKIP. He had clearly played an important role in securing the referendum, but he was also a big turn off for undecided voters. We also knew that senior figures flirting with joining us would never join an organization run by the UKIP leader.

Multiple attempts to combine the different factions failed. In early 2016, Tory MPs considered merging with UKIP until they realized all the campaign staff were loyal to Dom Cummings, Vote Leave’s Campaign Director, and would walk without him. On another occasion, Vote Leave’s CEO, Matthew Elliot, gave a presentation to UKIP MEPs suggesting they might back us to be the official campaign. Farage arrived late, flanked by his security detail and two aides, and demanded to be on TV more and to know why we had never retweeted him.

He then proceeded to draw Cummings into an argument about whether we should propose a second referendum on the substance of the deal and accused us of not really wanting to leave the EU. A carefully orchestrated attempt to make peace was turned into an ugly showdown, and Farage’s eventual successor Paul Nuttall was left to try to calm things down by offering to mediate between the two warring camps.

By the time Cameron travelled to Brussels to speak to his European counterparts at the February summit, Cummings and I were convinced that unless the referendum was called soon, our campaign might not survive the infighting.

“The cavalry are coming mate, we’ve got to believe,” was our regular refrain in midnight taxis home as we prayed that senior Conservative politicians like Michael Gove and Boris Johnson would join us. Had Cameron taken Sir Lynton Crosby’s advice, rejected the deal and demanded more from the EU, he would probably have gotten his wish that Nigel Farage would lead the Leave campaign.

The economy, stupid

We were constantly told by well-meaning people on our own side that we needed to come up with a good response to the Remain camp’s powerful message that three million jobs would be lost if Britain left the EU. We ignored them. And with good reason.

Remainers were trying to lure us into a defensive position by asking us to outline a model for life outside the club. Did we want to be like Norway, Switzerland or Iceland? When I met with friends who worked in No. 10 they were incredulous that we would not set out a detailed framework for life outside the EU.

Instead, we refused to play their game and stuck to broad principles: We wanted control of our borders, free-trade deals and to take back control of the huge sums of money we sent to the EU every week. This wasn’t an attempt to ignore economic arguments but to play them on our terms.

Telling people about the large amount of money they sent to the EU every year was an extremely persuasive economic argument. It ran with the grain of public psychology on the EU. They knew successive prime ministers had fought to reduce the EU’s budget but it kept going up. They knew we put in more than we got back. They knew the EU did not spend their money wisely.

Of course, our campaign claim of the now infamous £350 million a week that Britain sends to the EU was not completely accurate. It was an underestimate. According to the Office for National Statistics. our total contribution to the EU is £19.1 billion a year — or £367 million a week.

As we explained regularly, this did not take into account the money the EU spent in the U.K. or the money that we get back in rebates. It was the total amount. The logic is the same as when you are offered a new job — you normally tell your spouse the gross salary you have been offered, not the net amount you receive after income tax, national insurance and pension contributions have been deducted.

I would wager that very few swing voters went to the polling booth and decided to vote Remain at the last minute because they were worried that we might end up with the “Norwegian option.”

The Remain campaign couldn’t stand it. They constantly tried to rubbish these official statistics and accused us of “lying.” These attacks were entirely counterproductive for them; it kept the debate focused on an area where we were strong: just how many hundreds of millions of pounds the U.K. gives the EU every week.

I would wager that very few swing voters went to the polling booth and decided to vote Remain at the last minute because they were worried that we might end up with the “Norwegian option.”

By the numbers

Most people thought we were crazy when we launched 50million.com, a game of skill that offered a £50-million prize — the amount we send the EU every day — if someone managed to correctly predict the outcome of every game at the European Football Championships. In fact, it was a very cost effective way of contacting a difficult-to-reach group of voters who do not normally engage in politics.

We asked them how they intended to vote as well and this data turned out to be crucial in validating our models.

When we started, we had no data, no activists and no systems. This made our job much harder at the beginning, but by the end it meant that we had a better, more coordinated database that was ready just in time.

Most political parties have to use a number of different legacy systems that do not speak to each other, leading to fragmentation and inefficiency. We had to spend a huge amount of time and resources building our systems from scratch, but when it was finished it allowed us to pool all our data into one system, giving us much more accurate modeling.

Meanwhile, our ground team built a grassroots army from scratch in less than six months, finding people who were politically active and encouraging them to volunteer. When we knocked on people’s doors and asked them how they intended to vote or when people clicked on our online adverts that data was all fed back into the system.

Our data allowed us to run webbots through public statistics from previous elections to find areas with high turnout and then matched this against our model of how Euroskeptic each part of the country was. We then focused our Get Out The Vote operations in half the country, focusing on individual households.

By the time of the referendum, we had campaign coordinators in 98 percent of parliamentary constituencies in the UK. On polling day itself, we had nearly 12,000 people knocking on doors. We had also held “dawn raids” across a quarter of the country to deliver leaflets so that our messages would be on people’s doormats when they got up for work. We were also able to send out over 500,000 text messages on polling day encouraging people to vote thanks to the new data we’d collected.

The Remain campaign, on the other hand, handed stickers and balloons out to everyone going in and out of tube stations across London. That might have made them feel good about themselves but it was a rookie error. Some 40 percent of people in London were leave voters, and they were reminding them to go and cast their votes.

The cavalry

In the early part of 2016, we felt like minnows. While the government machine gave huge muscle to the Remain campaign our team of 30 had to arrange everything. Our ministers were not allowed to use their ministerial cars or be seen at Leave campaign events during their official working time. Boris Johnson was tied up after promising Zac Goldsmith he would join him on the London mayoral campaign for most of April.

In a taxi home one night, Dom and I discussed how we could wrestle back the momentum. We knew the story journalists were most interested in was who would be the next prime minister so we decided to come up with some policy ideas that Johnson, Michael [Gove] and our chair, Gisela Stuart, could announce together.

We may have started the campaign dogged by stories of infighting but we were back on the attack just as postal ballots went out and voters were really listening.

Our strategy was to lay out an alternative vision for government by detailing policy suggestions that could be pursued after a Brexit vote, including extra funding for the NHS, a cut in VAT on fuel and an Australian-style points based immigration system.

The playbook of policy announcements was tried and tested – but we broke the rules by getting leading governing politicians to set out a manifesto while still serving the sitting prime minister. We had found a vehicle that allowed us to dominate the airwaves and move the debate back into areas where we were strong – the cost of the EU and the benefits of taking back control – and, crucially, we caught the government on the hop. Their response was confused and they lashed out at Boris [Johnson] and Michael [Gove].

Dom had been arguing for weeks that we needed to “pick up a baseball bat with the words immigration and the NHS written on it and smash it over the In campaign.” Boris and Michael could only be persuaded to do that when they came under heavy fire from No. 10 six weeks out.

We may have started the campaign dogged by stories of infighting but we were back on the attack just as postal ballots went out and voters were really listening. The cavalry arrived after all, and just in time to carry us over the line.

Paul Stephenson was the communications director for Vote Leave, the official Brexit campaign.