President Vladimir V. Putin’s confidence seems to know no bounds.

Buoyed by Ukraine’s failed counteroffensive and flagging Western support, Mr. Putin says that Russia’s war goals have not changed. Addressing his generals on Tuesday, he boasted that Ukraine was so beleaguered that Russia’s invading troops were doing “what we want.”

“We won’t give up what’s ours,” he pledged, adding dismissively, “If they want to negotiate, let them negotiate.”

But in a recent push of back-channel diplomacy, Mr. Putin has been sending a different message: He is ready to make a deal.

Mr. Putin has been signaling through intermediaries since at least September that he is open to a cease-fire that freezes the fighting along the current lines, far short of his ambitions to dominate Ukraine, two former senior Russian officials close to the Kremlin and American and international officials who have received the message from Mr. Putin’s envoys say.

In fact, Mr. Putin also sent out feelers for a cease-fire deal a year earlier, in the fall of 2022, according to American officials. That quiet overture, not previously reported, came after Ukraine routed Russia’s army in the country’s northeast. Mr. Putin indicated that he was satisfied with Russia’s captured territory and ready for an armistice, they said.

Mr. Putin’s repeated interest in a cease-fire is an example of how opportunism and improvisation have defined his approach to the war behind closed doors. Dozens of interviews with Russians who have long known him and with international officials with insight into the Kremlin’s inner workings show a leader maneuvering to reduce risks and keep his options open in a war that has lasted longer than he expected. While deploying fiery public rhetoric, Mr. Putin privately telegraphs a desire to declare victory and move on.

“They say, ‘We are ready to have negotiations on a cease-fire,’” said one senior international official who met with top Russian officials this fall. “They want to stay where they are on the battlefield.”

There is no evidence that Ukraine’s leaders, who have pledged to retake all their territory, will accept such a deal. Some American officials say it could be a familiar Kremlin attempt at misdirection and does not reflect genuine willingness by Mr. Putin to compromise. The former Russian officials add that Mr. Putin could well change his mind again if Russian forces gain momentum.

In the past 16 months, Mr. Putin swallowed multiple humiliations — embarrassing retreats, a once-friendly warlord’s mutiny — before he arrived at his current state of relaxed confidence. All along, he waged a war that has killed or maimed hundreds of thousands while exhibiting contradictions that have become hallmarks of his rule.

While obsessed with Russia’s battlefield performance and what he sees as his historic mission to retake “original Russian lands,” he has been keen for most Russians to go on with normal life. While readying Russia for years of war, he is quietly trying to make it clear that he is ready to end it.

“He really is willing to stop at the current positions,” one of the former senior Russian officials told The New York Times, relaying a message he said the Kremlin was quietly sending. The former official added, “He’s not willing to retreat one meter.”

Mr. Putin, the current and former officials said, sees a confluence of factors creating an opportune moment for a deal: a battlefield that seems stuck in a stalemate, the fallout over Ukraine’s disappointing offensive, its flagging support in the West, and, since October, the distraction of the war in Gaza. The officials spoke on the condition of anonymity, like others interviewed for this article, because of the sensitive nature of the back-channel overtures.

Responding to written questions after declining an interview request, Mr. Putin’s spokesman, Dmitri S. Peskov, said in a voice message that “сonceptually, these theses you presented, they are incorrect.” Asked whether Russia was ready for a cease-fire at the current battle lines, he pointed to the president’s recent comments; Mr. Putin said this month that Russia’s war goals had not changed.

“Putin is, indeed, ready for talks, and he has said so,” Mr. Peskov said. “Russia continues to be ready, but exclusively for the achievement of its own goals.”

Ukraine has been rallying support for its own peace formula, which requires Moscow to surrender all captured Ukrainian territory and pay damages. President Volodymyr Zelensky said Tuesday that he saw no sign that Russia wanted to negotiate.

“We just see brazen willingness to kill,” he said.

Mr. Putin first explored peace talks in the early weeks of the war, but they fell apart after Russia’s atrocities in Ukraine came to light. Then, in the fall of 2022, after Russia’s embarrassing retreat from northeastern Ukraine, Mr. Putin again sent messages to Kyiv and the West that he would be open to a deal to freeze the fighting, American officials say.

Some of Ukraine’s supporters, like Gen. Mark A. Milley, then the chairman of the Joint Chiefs of Staff, encouraged Kyiv to negotiate because Ukraine had achieved as much on the battlefield as it could reasonably expect. But other top American officials believed it was too soon for talks. And Mr. Zelensky vowed to fight on until the entire country had been freed from Russia’s grasp.

By early 2023, gloom had settled over Moscow. On eastern Ukraine’s frozen plains, much of Russia’s prewar professional force had been decimated, leaving poorly trained draftees and convicts recruited from prisons to be gunned down in haphazardly planned infantry storms.

Mr. Putin said little in public about the war, stoking questions about his plans and motivations. In private, though, Mr. Putin embraced his role as commander in chief with an almost messianic determination during these months, the people close to the Kremlin contend. One said last February that the president held two videoconferences a day with military officials who briefed him on the minutiae of movements on the battlefield.

The war was “impossible to stop,” the person said, describing a conversation with a top Russian military official, because Mr. Putin “remains consumed by all this.”

“People want to tell him only good news, and there’s not much of that,” the person said. “So you have to lie.”

Sergei K. Shoigu, the Russian defense minister, made clear in a private meeting earlier this year that, despite his setbacks, Mr. Putin was determined to keep fighting. According to the senior international official, who was present, Mr. Shoigu gave statistics showing Russia’s advantage in tanks and warplanes and its plans to increase defense production. He boasted that Russia could mobilize as many as 25 million men, the official recalled.

“For Putin, it’s about Russia versus the U.S. and the West,” the official said after the meeting. “Putin can’t afford to back down.”

As Ukraine launched its long-anticipated counteroffensive in June, Mr. Putin appeared tense, anxious for battlefield updates, people close to the Kremlin said. In public, Mr. Putin became a live commentator of the fight, eager to claim incremental successes.

“The enemy is trying to attack,” Mr. Putin said onstage at his marquee St. Petersburg International Economic Forum on June 16, describing a battle happening “right now.” “I think the armed forces of Ukraine have no chance.”

The same day, a delegation of African leaders arrived in Kyiv hoping to broker peace. At one point, Ukrainian officials rushed them into a shelter, warning of an attack. The next day, in St. Petersburg, President Cyril Ramaphosa of South Africa asked Mr. Putin whether he had really bombed the Ukrainian capital while the African leaders were there.

“Yes, I did,” Mr. Putin responded, according to two people close to Mr. Ramaphosa, “but I made sure it was very far from where you were.”

He still tried to play the gracious host, taking the leaders on a dinner cruise. A member of the African delegation said Mr. Putin seemed interested in preparing a channel for future talks.

“It’s not that I want to negotiate,” the person said, describing Mr. Putin’s stance. “But I need to have ready, when the time will come, a very well-conceived, intelligent, capable channel of negotiations.”

A week later, the mercenary warlord Yevgeny V. Prigozhin launched his failed mutiny.

After Mr. Prigozhin accepted a deal to retreat to Belarus, Mr. Putin proceeded to spin what seemed to be one of the most humiliating moments of his 24 years in power into a victory. He declared in a lavish Kremlin ceremony that the failure of the rebellion demonstrated the strength of the Russian state. It offered a hint of what Mr. Putin might do if he fell short of his original goals in Ukraine: declare victory and move on.

The Kremlin’s analysis appeared to be that public support for the war was broad, but not deep — meaning that most would accept whatever Mr. Putin termed a victory. One of the government’s pollsters, Valery Fyodorov, said in a September newspaper interview that only 10 to 15 percent of Russians actively supported the war, and that “most Russians are not demanding the conquest of Kyiv or Odesa.”

By the end of the summer, events were shifting in Mr. Putin’s favor. Mr. Prigozhin’s death in a plane crash, widely seen as the Kremlin’s doing, eliminated his most dangerous domestic foe. On the battlefield, Russia already appeared to be successful in repelling Ukraine’s counteroffensive.

Mr. Putin and his government exuded stability and confidence. The president continued to go for his morning swims, several people with knowledge of his schedule said. Top Kremlin officials had gone back to taking vacations.

“They’ve calmed down already,” Prime Minister Akylbek Zhaparov of Kyrgyzstan said in an interview in October, referring to the surprise and worry among many Russian officials and the elite when Mr. Putin invaded Ukraine last year. After first seeing Mr. Putin’s war as a “catastrophe,” he added, “they’ve now gotten used to it.”

On a Saturday in October, Mr. Putin marked his 71st birthday with the leaders of Uzbekistan and Kazakhstan, two Central Asian countries that have tried to take a neutral stance in the war. When they arrived at his suburban Moscow residence, Mr. Putin got behind the wheel of a new Russian-made limo, showing off one of the ways in which, in the Kremlin’s telling, Russia is becoming more self-sufficient.

Once indoors, the three leaders spoke about a plan to sell Russian gas to Uzbekistan. A person present recalled Mr. Putin’s calm confidence and relaxed body language.

“He doesn’t look like a man who’s waging war,” the person said.

Only after a birthday lunch did they grasp the full significance of events elsewhere. It was Oct. 7.

The terrorist attack by Hamas that day — and Israel’s fierce military response — proved to be a propaganda boon for Russia, pulling attention away from Ukraine and allowing Mr. Putin to line up with much of the world in condemning the bombardment of Gaza and American support for Israel.

“He sees that the attention of the West is turning away,” said Balazs Orban, an aide to Prime Minister Viktor Orban who participated in the Hungarian leader’s meeting with Mr. Putin in October.

In late October, Grigory A. Yavlinsky, a liberal Russian politician, waited past midnight for an audience at the Kremlin. He said he tried to impress upon Mr. Putin the scale of the Russian deaths in Ukraine, which dwarfed Soviet losses over a decade of war in Afghanistan.

Then Mr. Yavlinsky made what he said was his central pitch in the 90-minute meeting: If Mr. Putin were prepared “at least to think about a cease-fire,” Mr. Yavlinsky, who was born in western Ukraine, would be ready to act as a negotiator.

“The fact that he agreed to talk to me for so long speaks for itself,” he said.

Since at least September, Western officials have been picking up renewed signals that Mr. Putin is interested in a cease-fire.

The signals come through multiple channels, including via foreign governments with ties to both the United States and Russia. Unofficial Russian emissaries have spoken to interlocutors about the contours of a potential deal that Mr. Putin would accept, American officials and others said.

“Putin and the Russian army, they don’t want to stretch their capacity further,” said the international official who met with top Russian officials this fall.

Mr. Putin has also made vague public comments about being open to negotiations, which have largely been dismissed by Western commentators.

Some analysts argue that Mr. Putin benefits from a long war, and that he wants to delay any negotiation until a possible return to office by former President Donald J. Trump, the front-runner for the Republican presidential nomination in 2024. The former Russian officials said that Mr. Putin would prefer to strike a deal sooner, given the uncertainty inherent in war.

They said that Mr. Putin’s propaganda could easily spin the status quo as a victory, celebrating a land corridor to Crimea, an army that withstood Ukraine’s Western-supplied counteroffensive and Russia’s claimed annexation of four Ukrainian regions — papering over the fact that Russia doesn’t fully control them.

The ideal timing, one of the people said, would be before Russia’s presidential election in March. Mr. Putin is certain to secure another six-year term, but he cares deeply about the election as a marker of his domestic support.

Publicly, Mr. Putin has stuck to his aggressive stance, saying he is resisting a West seeking to destroy a 1,000-year-old Russian civilization.

But American officials see a shift in Mr. Putin’s position, noting that he is no longer demanding the departure of Mr. Zelensky’s government. They said that the cease-fire being floated by Mr. Putin would maintain a sovereign Ukraine with Kyiv as its capital, but leave Russia in control of the nearly 20 percent of Ukrainian territory it has already conquered. They added that while Mr. Putin is telegraphing that he is open to such a deal, he is waiting to be brought a more specific offer.

Among the many likely sticking points is Mr. Putin’s determination to keep Ukraine out of NATO. But one of the former Russian officials said a disagreement on that score would not be a deal breaker for Mr. Putin, because the alliance is not expected to admit Ukraine in the foreseeable future.

Still, senior American officials said they did not believe that any prominent Ukrainian politician could agree at this time to a deal leaving Russia with so much Ukrainian territory.

Another potential impasse stems from Mr. Putin’s efforts to put the United States at the center of any negotiations.

The U.S. and Russian governments have channels for communications on issues that include prisoner swaps. But William J. Burns, the director of the Central Intelligence Agency, and Sergei Naryshkin, the director of Russia’s foreign intelligence service, last met about a year ago in Turkey, officials said. And U.S. officials say the United States has not and will not negotiate on behalf of Ukraine.

American officials argue that regardless of Mr. Putin’s overture, Ukraine must demonstrate its staying power, and the United States must show it is willing to support Ukraine to puncture Mr. Putin’s confidence that time is on his side and to force concessions in any negotiations.

Many in the West are skeptical of a cease-fire because they say Mr. Putin would rearm for a future assault. President Edgars Rinkevics of Latvia argued in an interview that Mr. Putin was committed to war because he dreams of “re-establishing the empire.”

“They never honored any agreements,” Mr. Rinkevics said of the Russians, “and they have violated them immediately when they saw it was convenient.”

Reporting was contributed by Neil MacFarquhar, John Eligon, Declan Walsh, Andrew E. Kramer and Valerie Hopkins.