Ohio Gov. John Kasich spoke with supporters after his surprise second-place finish in the GOP New Hampshire primary. (Reuters)

John Kasich was “irrelevant” in Donald Trump’s assessment three months ago. After a second-place finish Tuesday, Kasich has a rejoinder: Not anymore.

For months, the Ohio governor was the un-Trump, trying to stay positive while quietly and methodically building a New Hampshire base the old-fashioned way — one town hall meeting at a time.

He skipped the Iowa caucuses, betting that his centrist, laid-back brand wouldn’t break through in that conservative bastion. Meanwhile, back in New Hampshire, he sneaked up from behind the pack, designing a data-driven campaign to target Republicans and independents alike.

In the end, when voters here tuned in most intensely in the closing days, Kasich was in position to grab them. A quarter of the GOP electorate decided late, and Kasich performed strongly among them, according to network exit polls.

“There’s magic in the air with this campaign,” a jubilant Kasich said Tuesday night.

Republican presidential candidate Jeb Bush addressed supporters following the New Hampshire primary. (Reuters)

Kasich had maintained that he had “my own lane” in the GOP field, bristling at the suggestion that he should be lumped in with fellow establishment-friendly candidates, including the two others with gubernatorial experience, Jeb Bush and Chris Christie, as well as Sens. Marco Rubio (Fla.) and Ted Cruz (Tex.).

For now, his finish puts him on top of that pack.

But Kasich still placed far behind the front-runner Trump. And he faces a far greater challenge. He must compete in less-hospitable Southern territory before heading to his home ground of the Midwest.

And, after being mostly ignored by Trump and the rest of the field, he is bound to come under sustained assault from the competition, prompting a deeper examination of his record than occurred here, and testing his vow to remain “on the sunny side of the street.”

Nor did Kasich pull far enough ahead to shake off Bush and others competing to be the party’s Trump alternative.

Kasich had been the only candidate to explicitly vow to drop out if he performed poorly in New Hampshire. Now he and the other leading candidate plan to head to the next primary, in South Carolina on Feb. 20, and beyond. Christie, with a more disappointing finish in New Hampshire, is expected to decide Wednesday whether to continue.

Before Tuesday, the trio with gubernatorial experience had pitched their executive background and belittled the talka­thon role of the senators, Rubio and Cruz, all while Trump held a wide lead.

Republican presidential candidate Chris Christie addressed supporters following the New Hampshire primary. (Reuters)

Bush, who entered the race with high expectations and was backed by a super PAC that had more than $100 million, was briefly in first place in the polls before plummeting, hurt both by voter wariness of extending a family dynasty and by an anti-establishment mood that helped Trump’s rise. Trump hammered at Bush’s proposal to provide a path to citizenship or legal status to 11 million illegal immigrants, and he lampooned Bush as “low-energy.”

Christie, while performing worse than he had hoped, played a vital role in the political dynamics of the race by taking on the attack role that Kasich eschewed. Christie savaged Rubio in Saturday’s debate for a robotic performance. That may have taken votes away from Rubio — some of which may have gone to Kasich.

Bush advisers also seized on Rubio’s performance, saying it proved their argument that the senator’s carefully crafted image masked inexperience and raised questions about whether he would be able to hold his own against a Democratic opponent.

Bush advisers dismissed the importance of Kasich’s showing here, arguing that Bush has the resources to run a national campaign while Kasich does not.

Bush’s South Carolina operation is led by Brett Doster, a longtime aide who was responsible for driving Bush across Florida during his failed 1994 gubernatorial campaign. In addition to the operation built by his team in the past seven months, they’ve recently inherited a political operation led by Sen. Lindsey O. Graham (R-S.C.), whose aides and donors have fallen into line with the Bush camp across the state.

Graham said in an interview Tuesday that Kasich will fade as the campaign moves south.

“Of the three early states, South Carolina has always been Jeb’s best, in terms of infrastructure and dynamics,” Graham said. “We have a reputation for voting for the most conservative candidate who’s electable. John’s a good guy, and a good governor, but when it comes to military issues, he’s been more of a budget-cutter than a hawk.”

That was a knock, with an eye on South Carolina as a ­pro-military state, at Kasich’s comments in September that the government should consider whether there is “excess infrastructure” being paid for in the military budget.

Kasich has spent months overshadowed by his rivals. He entered the race over the summer as Bush began his slide, telling voters here that, “frankly, I thought Jeb was just going to suck all the air out of the room, and it just hasn’t happened.”

He had won a hard-fought gubernatorial election in 2014, leaving him a battle-tested team that has transferred its skills to the presidential bid.

In New Hampshire, Kasich’s campaign strategy was months in the making — identifying potential supporters, cultivating them and turning them out.

“There’s a science to it, but a lot of it is just sweat and work — it’s calling people, it’s knocking on doors,” Kasich adviser Tom Rath said. “In many ways here you treat an independent voter like you treat a Republican — they’re a potential voter.”

As he campaigned here, Kasich unabashedly walked the middle of the road on two touchstone issues for conservatives— immigration and health care.

Kasich has aggressively rejected the feasibility of deporting 11 million undocumented immigrants living in the United States.

He has instead advocated strengthening border control while giving such immigrants a path to legalization so long as they meet certain conditions and pay back taxes.

Kasich’s greatest vulnerability in the Republican primaries relates to his decision to expand Medicaid in Ohio under provisions created by the Affordable Care Act. The governor has been lambasted by critics who accuse him of increasing the size of government in the state; Kasich instead says his decision was based on the premise that accepting the $13 billion offered by the federal government would serve the dual purposes of helping to balance the state’s budget while fulfilling a moral duty to its poorest citizens. Anticipating the battle ahead, Bush’s campaign on Sunday posted a Web-only ad that criticized Kasich’s decision to accept the money.

David Weigel and Ed O’Keefe contributed to this report.