How on earth did Barack Obama, the community organizer, harness the power of data in the 2012 election like a Bain Capital numbers-cruncher, while Mitt Romney’s data-mining effort crashed and burned like, well, Solyndra?

While Romney was relying on false signs of Republican “enthusiasm” and “momentum,” Obama was playing a game of political “Moneyball” — using an analytical, metrics-based approach to assemble a winning campaign, the way Billy Beane’s Oakland A’s used rigorous statistical analysis to assemble a winning baseball team.

According to Time magazine, the Obama campaign undertook an unprecedented data-mining effort that helped the president “raise $1 billion, remade the process of targeting TV ads and created detailed models of swing-state voters that could be used to increase the effectiveness of everything from phone calls and door knocks to direct mailings and social media.”

The Obama operation (code-named “Narwhal” for the Arctic whale with a long spiral tusk) merged “information collected from pollsters, fundraisers, field workers and consumer databases as well as social-media and mobile contacts with the main Democratic voter files in the swing states” into a single massive database, Time reported.

The Obama team then fed the data into advanced predictive models that allowed officials to target voters with specialized messages. For example, the Obama campaign could identify the Planned Parenthood supporters living within largely Christian Zip codes and send them e-mails about Romney’s “war on women” without the risk of alienating pro-life Reagan Democrats who might recoil from such language.

Narwhal also gave the Obama campaign unprecedented insight into how voters were moving as the campaign progressed. Polling organizations such as Gallup typically use a sample of 1,000 voters nationally to follow electoral trends. The Obama team developed a polling-data profile of 29,000 voters in Ohio alone and used this information to follow how various target groups were trending, how they responded to different messages and how events such as the presidential debates were moving the electorate — so they could respond effectively.

The system proved so accurate, Obama strategist David Axelrod declared, that “nothing happened on election night that surprised me — nothing. Every single domino that turned over was in keeping with the model that our folks had projected.”

What about Mitt Romney? How did the metrics-driven business executive tap into the power of data? The Romney campaign called its data-mining effort Project ORCA (for the Arctic killer whale that is the narwhal’s natural predator — get it?) and boasted that it would “ensure hyper-accuracy of our supporter targeting as we work to turn them out to the polls.” One Romney official even mocked the Obama data project, declaring, “The Obama campaign likes to brag about their ground operation, but it’s nothing compared to this.”

Well, the Obama operation was nothing like ORCA — because it worked. According to ABC News, ORCA crashed when its data servers overloaded. “So much data was coming in, the system thought it was under attack,” a campaign official told the network.

It turns out ORCA had not been fully tested before Election Day.

Reports from the field were devastating. One volunteer told, “I worked on the Colorado team, and we were called by hundreds (or more) volunteers who couldn’t use the app or the backup phone system. The usernames and passwords were wrong, but the reset password tool didn’t work, and we couldn’t change phone PINs. . . . Then at 6 pm they admitted they had issued the wrong PINs to every volunteer in Colorado, and reissued new PINs (which also didn’t work).”

Another volunteer, John Ekdahl, wrote a blistering account of his experience on the Ace of Spades blog, concluding that “30,000+ of the most active and fired-up volunteers were wandering around confused and frustrated when they could have been doing anything else to help [l]ike driving people to the polls, phone-banking, walking door-to-door, etc.” The result? Romney was flying blind on Election Day.

Mitt Romney was not the cool candidate. He ran on competence. But having the data system your campaign is relying on to turn out the vote crash on Election Day is incompetent. Not testing that system before Election Day is inexcusable. And letting a community organizer run a more precise, data-driven, metrics-based campaign than a Bain Capital executive is incomprehensible.

In the coming months, Republicans will spend a lot of time studying why they lost and debating whether they should reposition themselves on issues like immigration. Those are discussions worth having. But they won’t matter one iota if the GOP can’t find a way to join the Democrats in the information age. In 2012, the Republicans were like a bag phone to Obama’s iPhone — when they needed to be a Samsung.

Asked by Politico’s Mike Allen what the biggest lesson someone running 2016 should learn from the Obama campaign, David Axelrod said: “I would invest in people . . . who understand where the technology is going and what the potential will be by 2016 for communications, for targeting, for mining data, to make precision possible in terms of both persuasion and mobilization.”

That is advice Republicans had better heed.

Marc A. Thiessen, a fellow with the American Enterprise Institute, writes a weekly online column for The Post.