Reeling from their losses in Tuesday's Democratic and Republican primaries, Senator Bernie Sanders of Vermont and Senator Ted Cruz of Texas abruptly reordered their campaigns on Wednesday, aiming to preserve some small hope that the race might yet turn in their favor.
Mr. Cruz named a running mate, Carly Fiorina, to help bring down Donald J. Trump, the Republican favorite, and both spoke of Mr. Trump in the language of relentless opposition, casting him as a sinister figure who must not be allowed to become president.
On the Democratic side, Mr. Sanders said he would scale back his upstart bid for the White House and lay off hundreds of campaign workers, a measure seemingly intended to extend the life of his candidacy but not to prepare for a general election.
In an interview, Mr. Sanders acknowledged in the strongest terms yet that Hillary Clinton's delegate lead might have closed off his path to the nomination, and he was less combative toward his party's front-runner in his moment of apparent defeat, taking a tone of cold realism, if not quite resignation.
Stymied in his efforts this week to challenge Mrs. Clinton's dominance in the urban Northeast, Mr. Sanders said he would now refocus his efforts chiefly on the June 7 primary in California, a state laden with both delegates and political symbolism. By winning there, he said, he hoped to strengthen his hand ahead of the Democratic convention in Philadelphia, where he would push his core priorities into the party platform.
"If we can win the largest state in this country, that will send a real message to the American people," Mr. Sanders said, "and to the delegates that this is a campaign that is moving in the direction it should."
The Sanders campaign said late Wednesday that it would continue to maintain a staff of more than 300 as the race moved toward California. The campaign had roughly 1,000 workers during the initial nominating contests.
Mr. Sanders did not rule out a comeback before the end of primary voting in June. But he has appeared to tone down his antagonism of Mrs. Clinton in recent days, abandoning his brief attacks on her qualifications for the presidency and instead focusing on her policy stances and ties to Wall Street.
If Mr. Sanders seemed on Wednesday to bow to political reality on the Democratic side — and to Mrs. Clinton's apparent inevitability as the party's nominee — Mr. Cruz took a far more defiant line in the Republican race.
Walloped by Mr. Trump in the last six primaries and lagging behind him in polls before next week's contest in Indiana, Mr. Cruz made a daring but somewhat desperate announcement: that in the event of his nomination, Mrs. Fiorina, the former Hewlett-Packard executive, would be his vice-presidential running mate.
Appearing alongside Mrs. Fiorina in Indianapolis, Mr. Cruz delivered a stemwinder of a speech, castigating Mr. Trump as an untrustworthy narcissist. He and Mrs. Fiorina jointly criticized the news media for rushing to treat Mr. Trump's victory in the nomination fight as a foregone conclusion.
The Republican race, Mrs. Fiorina said, was a struggle "for the soul of our party and the future of our nation."
By rushing out a vice-presidential pick before the Indiana vote, which is becoming make-or-break for his candidacy, Mr. Cruz opted to tear open his party's divisions even more widely, rather than to stand down in view of Mr. Trump's growing strength.
Mr. Cruz's criteria for a pick, in his telling, seemed to be aimed squarely at Mr. Trump. "Do they think through decisions in a rash and impulsive way?" he asked. "Do they pop off the handle at whatever strikes them at any given moment?" He held up Mrs. Fiorina as someone who knows "where jobs come from."
Mr. Cruz's selection of Mrs. Fiorina may present a perilous challenge for Mr. Trump, who is grappling with mounting criticism of his derisive remarks about women, including his repeated claims that Mrs. Clinton's sole political asset is "the woman's card."
Mindful of the gender gap often evident in Mr. Trump's polling, Cruz allies hope that Mrs. Fiorina will prove a capable foil to him, as she did while besting him in a series of debate exchanges during her own candidacy. Since endorsing Mr. Cruz last month, Mrs. Fiorina has proved to be an eager surrogate, attacking Mr. Trump and Mrs. Clinton with zeal.
Mr. Trump, viewed unfavorably by most women in general election polls, has clashed savagely with Mrs. Fiorina in the past. He has mocked her business record, her voice and even her looks. "Look at that face," Mr. Trump said in an interview with Rolling Stone magazine last summer. "Would anyone vote for that?"
Another slashing comment directed at Mrs. Fiorina's appearance or gender could have grave consequences for Mr. Trump, especially with female voters he would need to win over to compete in the fall.
Mr. Trump responded to the surprise announcement with a degree of restraint. Referring to the "new relationship" between "Cruz and Carly," Mr. Trump shook his head and raised his eyebrows as he dismissed the move.
"He has set a record," Mr. Trump said of his opponent. "He is the first presidential candidate in the history of this country who's mathematically eliminated from becoming president who chose a vice-presidential candidate."
Mr. Cruz's gambit was received chiefly as an act of beleaguered improvisation — the political equivalent of a student pulling a fire alarm to avoid an exam.
In the short term, Mr. Cruz may have succeeded in shifting the focus away from Mr. Trump's success in the last two rounds of voting, and from his own wheezing alliance with Gov. John Kasich of Ohio, who agreed to clear out of Indiana if Mr. Cruz withdrew from competition in Oregon and New Mexico.
Yet his partnership with Mrs. Fiorina may prove of limited value if Mr. Trump clobbers them both in Indiana, where 57 delegates are at stake. Mr. Trump already leads Mr. Cruz by more than 400 delegates, and has gathered more than three-quarters of the delegates he needs to clinch the Republican nomination.
Mr. Cruz acknowledged in his speech on Wednesday that he no longer had a chance of winning the 1,237 delegates required to become the nominee, but said he still planned to challenge Mr. Trump in an open convention.
With his announcement, Mr. Cruz becomes the first candidate in 40 years — since Ronald Reagan in 1976 — to name a running mate before capturing his party's nomination.
Far more conventional is Mr. Sanders's shift toward a strategy of dogged and benign persistence, rather than aggressive confrontation with Mrs. Clinton. Candidates for president routinely scale back their campaigns but forge ahead because they hope to advance a specific policy agenda, or out of a sense of obligation to their supporters.
Mrs. Clinton, for one, insisted on fighting the 2008 Democratic race all the way through the last day of primary voting, even after Barack Obama had gained a permanent upper hand in the competition for delegates.
Yet few losing candidates in recent memory have generated the kind of electric energy within the Democratic base that Mr. Sanders has in the 2016 election. Democratic leaders are especially sensitive to his following among young people, who have voted for him by staggering margins, and whose support Mrs. Clinton may rely on against Mr. Trump in the November election.
Even if Mr. Sanders shies away from direct conflict with Mrs. Clinton, he could still be an irksome presence in the race. He is likely to win several primaries in May, and a large-scale effort in California could pressure Mrs. Clinton to spend time and money there to forestall an embarrassing upset.
But unlike Mr. Trump, who appears determined to batter Mr. Cruz and Mr. Kasich into submission, Mrs. Clinton and her allies have taken a gingerly approach to Mr. Sanders in what seem to be the waning days of his campaign.
They have urged Mr. Sanders to sand down the sharpest edges of his arguments against Mrs. Clinton and begin to prepare the party for a moment of coming together in Philadelphia.
Gov. Jack Markell of Delaware, a Clinton supporter, said Democrats hoped for "a somewhat rapid conclusion" to the primaries, but viewed withdrawing from the presidential race as a "personal decision" for Mr. Sanders.
"Obviously, as you get to this point, you want to see all Democrats focused on the Republicans and not focused on each other," Mr. Markell said. Mr. Sanders, he added, "certainly believes that electing one of these Republicans as president would be a real nightmare for the country."
— Matt Flegenheimer and Jonathan Martin contributed reporting.