Gov. John Kasich of Ohio, a moderate voice who tried to portray himself as the adult in the Republican primary field but failed to win any state but his own, is ending his long-shot quest for the presidency on Wednesday, according to two people briefed on his decision.

Mr. Kasich’s departure, a day after Donald J. Trump’s victory in the Indiana primary, leaves Mr. Trump as the only candidate remaining in the Republican race. His closest challenger, Senator Ted Cruz of Texas, dropped out Tuesday night.

A conventional candidate in an unconventional race, Mr. Kasich outlasted the other governors in the Republican field. But his longevity was largely a testament to his unbending refusal to drop out long after it became clear that voters were not flocking to his campaign.

He rarely wavered from his above-the-fray approach to his rivals, even as they racked up far more delegates. When his rivals attacked one another, Mr. Kasich struck a sunny tone and told people that they were made special by the Lord. When his opponents took polarizing and contentious positions, he emphasized his record as governor of Ohio and his long career in Congress.

Mr. Kasich, citing polls, had insisted he was the only remaining Republican candidate who could win in November. But while he expressed hope that voters in the Northeast would embrace his more moderate views, he was obliterated by Mr. Trump in the five states that held primaries last week, and he never matched Mr. Cruz as the main alternative to Mr. Trump.

In a last-ditch deal with Mr. Cruz, Mr. Kasich agreed not to compete in Indiana, a critical state for those hoping to stop Mr. Trump. Mr. Cruz, in exchange, agreed not to compete in two states with later contests, Oregon and New Mexico.

But Mr. Trump’s victory in Indiana put him in a commanding position to officially secure the nomination on June 7, when the last Republican contests will be held. Mr. Kasich’s only hope to win was at a contested convention, which appears increasingly unlikely.