A victorious Ted Cruz and buoyant Marco Rubio emerged from Iowa with compelling claims to the outsider and mainstream mantles in the fractured Republican primary, as the presidential race shifted overnight to New Hampshire. Democrats were girding for a protracted slugfest between Bernie Sanders and Hillary Clinton, locked in a virtual tie.

Donald Trump, uncharacteristically humble after a second-place Iowa finish, was headed for far friendlier territory in New Hampshire, where the billionaire firebrand had a commanding lead.

Amid historically large turnout in Iowa, the unexpected benefactor was Rubio, who came within striking distance of Trump. Republicans had already been looking to New Hampshire to winnow their congested field, and the Florida senator's strong showing bolsters his case that Republicans should coalesce behind him as the mainstream alternative to the rowdier Trump or Cruz.

"We have taken the first step, but an important step, to winning the nomination," Rubio told supporters in Des Moines.

Monday's Democratic contest was a cliffhanger - "The results tonight are the closest in Iowa Democratic caucus history," said state party chairman Andy McGuire - a far cry from the coronation for Clinton that most Democrats once expected.

Even with an elaborate campaign operation and backing from most Democratic Party leaders, Clinton was unable to stem a flood of enthusiasm from young and liberal voters for Sanders, the eccentric Vermont senator whose viability in a general election is still deeply questioned.

Cruz, the Texas conservative known for his scorched-earth approach to compromise, hoped his triumph in the Iowa caucuses would bolster his standing as the top choice of Republicans seeking an agitator to upend the legacy of eight years under President Barack Obama. Having run a textbook Iowa campaign targeting rural and evangelical voters, Cruz faced a steeper climb in New Hampshire, with its tradition of favoring more mainstream candidates.

"We've built our campaign as a movement for Americans to organize, rallying and banding together against the disaster of the Washington cartel," Cruz told The Associated Press as he made his way to New Hampshire.

Despite falling short of victory, Trump proved he could transform many of his die-hard fans into actual voters - the key question facing his campaign heading into Monday's voting. Yet the results raised an equally curious question: how Trump, who's branded himself as a reliable winner, can handle being a loser.

Thanking supporters at a rally, Trump displayed a rare hint of modesty as he congratulated Cruz and the other Republicans.

"We finished second, and I want to tell you something: I'm just honored," Trump said. "We're just so happy with the way everything worked out."

Although Clinton said she was "breathing a big sigh of relief," and her campaign said it had won an outright victory, the neck-and-neck contest was a blow, evoking the setback she faced in 2008 after her upset loss to then-Sen. Obama. Given the closeness of the Democratic caucuses, the AP did not declare a winner.

Eight years ago, Clinton's victory in New Hampshire breathed fresh life into her campaign. But New Hampshire is also familiar territory for Sanders, who represents neighboring Vermont in the Senate and is well known among the state's voters. Sanders' sizable lead over Clinton in New Hampshire polls has held steady or increased in recent weeks.

Nearly all the candidates planned to return to New Hampshire by midday Tuesday after hopping overnight flights from Iowa. Voters will hold the first primary of the season here on Feb. 9.

Behind Trump, who has led by double digits in New Hampshire in recent polls, the GOP race remained hotly contested. Facing dim prospects in Iowa, Chris Christie, John Kasich and Jeb Bush - all current or former governors - were laser-focused on New Hampshire.

Those three Republicans were clustered close together with Rubio and Cruz, separated by just a handful of percentage points in a CNN/WMUR poll conducted last week. Yet 6 in 10 Republicans said they hadn't yet made up their mind, suggesting plenty could change over the next seven days.

As the GOP winner in Iowa, Cruz collected at least eight of the state's 30 Republican delegates, with Trump winning seven and Rubio six. Democrats apportion their delegates differently, and even with no declared winner, the AP awarded Clinton 22 delegates and Sanders 21. The statewide winner will collect the final delegate.

New Hampshire's primary process, in which voters cast ordinary ballots, offers the candidates a more straightforward sprint toward victory than the quixotic Iowa caucuses. But undeclared voters, who make up the largest bloc in New Hampshire, can vote in either party's primary, infusing the race with an added level of uncertainty. Democrats have 24 delegates at stake in New Hampshire and Republicans have 23.

Both parties were offering New Hampshire voters a candidate roster that was shorter than a day earlier. Former Maryland Gov. Martin O'Malley, a Democrat, and former Arkansas Gov. Mike Huckabee, a Republican, both dropped out Monday night following dismal showings in Iowa.

Before voters in New Hampshire weigh in, candidates in both parties may have another opportunity to debate. Sanders and Clinton will likely square off Thursday at the University of New Hampshire. The Republicans will meet Saturday in Manchester.