As he prepares to retire to his California walnut farm this month, Defense Secretary Leon E. Panetta is still fighting the battle that has consumed his entire tenure at the Pentagon: an increasingly desperate campaign to persuade Congress not to whack defense spending.

In recent days, Panetta, 74, has uttered near-apocalyptic warnings about what will happen if Congress does not do something by March 1 to avert a “doomsday scenario” under which the Defense Department could be required to slash $43 billion in spending in the next seven months, and as much as $500 billion in the next decade.

Those cuts, he told lawmakers last week, would turn the mighty U.S. military “into a second-rate power” and would force the Obama administration to throw its entire national-security strategy “out the window.”

He has warned that naval operations in the Pacific would shrink by a third. All military training would slow to a crawl. And almost every civilian employee at Defense could be furloughed, as much as one day a week for the rest of the fiscal year.

At a farewell ceremony Friday at Fort Myer, President Obama praised Panetta, saying, “No one has raised their voice as firmly or as forcefully on behalf of our troops as you have.”

Obama also urged Congress to work out a new deal with him to avoid what he called “massive, indiscriminate cuts that could have a severe impact on our military preparedness.”

He added, “There is no reason, no reason for that to happen.”

It is the same message that Panetta has delivered, so far to no avail, almost every day since he took over as defense secretary in July 2011. The next month, he was saddled with the task of shrinking the military after Obama and Congress agreed to cut $487 billion in projected defense spending for the next 10 years.

But that was just the first swing of the ax. Under the rest of the deal, the Pentagon would be forced to cut $500 billion more in the same period if lawmakers and the White House could not come up with another, more palatable way to reduce the nation’s record deficits.

It appears highly unlikely that Congress and the White House will reach a deal to spare the Pentagon before Panetta retires. It will fall to his successor — Obama has nominated former senator Chuck Hagel (R-Neb.) for the job — to manage any further cuts. But Panetta’s failure to prevent what he described as the worst-case scenario will mark the end of an otherwise influential and colorful career in Washington that has spanned four decades.

The high point came in May 2011 when, as CIA director, Panetta oversaw the successful and daring strike that killed al-Qaeda leader Osama bin Laden. Along the way, he served as White House chief of staff during the Clinton administration and as chairman of the House Budget Committee, where he earned a reputation as a skillful negotiator on fiscal issues.

It was largely for his budget and legislative expertise that Obama tapped Panetta to lead the Pentagon, which now faces a wrenching consolidation after years of growth fueled by the wars in Iraq and Afghanistan.

As defense secretary and as CIA chief, the gregarious and guffaw-prone Panetta got along well with Congress. He was unanimously confirmed by the Senate to lead the Pentagon and maintained a good rapport even with the most hard-nosed lawmakers.

“I feel I’ve been jerked around by every CIA director,” Sen. Barbara A. Mikulski (D-Md.), groused during a hearing Thursday, “with the exception of Mr. Panetta.”

Panetta’s relationships on Capitol Hill, however, have been insufficient to overturn the automatic defense cuts. The legislative gridlock has prompted him to vent his criticism of Congress in more personal terms than in the past.

During a visit to a U.S. military base in Italy last month, he questioned lawmakers’ courage, contrasting their inaction to his troops’ willingness to give their lives for their country.

“You take the worst risks of all, which is that somebody may shoot you and you may die,” Panetta said. “It’s a hell of a risk. You know, all we’re asking of our elected leaders is to take a small part of the risk that maybe, you know, they’ll piss off some constituents.”

Panetta’s full-throated lobbying to preserve the defense budget has surprised some former colleagues, who remember his willingness to downscale the military after the Cold War when he served in Congress and later as budget director in the Clinton administration.

Gordon Adams, an American University professor of foreign policy who worked with Panetta at the White House in the 1990s, said he was “almost flabbergasted” by the defense secretary’s resistance to cuts this time around.

With the end of the wars in Iraq and Afghanistan, compounded by the nation’s heavy debts, Adams said Panetta should recognize that the Pentagon will inevitably have to downsize further.

“If you hear all of the rhetoric, you’d think the sky is falling,” Adams said. “But it’s not doomsday.”

In the short term, analysts said, the Pentagon may have made things more painful for the military by refusing to plan for the worst.

Throughout Panetta’s tenure, defense officials have assumed that Congress would eventually overturn the automatic cuts, so they kept spending at their usual rate instead of saving. Now, with the federal fiscal year almost half over, the Pentagon might have to slash $43 billion from its annual budget by the end of September instead of having a full year to absorb the reductions.

In effect, Panetta and the White House were betting that lawmakers would see the automatic defense cuts as so harmful that they would blink and change their minds. If the Pentagon had moved earlier to trim spending, it risked making the cuts appear manageable, analysts said.

“There is this sort of gamesmanship or brinkmanship that is involved,” said Andrew F. Krepinevich, president of the Center for Strategic and Budgetary Assessments, a national security think tank in Washington. “I think Panetta walked that line pretty well. It’s easy to understand why he’d want to delay.”

In a speech Wednesday at Georgetown University, Panetta made a last-ditch attempt to persuade Congress to come to the Pentagon’s rescue. He warned lawmakers that they risk a voter revolt if the cuts go forward, recalling public anger at the legislative gridlock that briefly shut down the federal government in 1995 and 1996.

“Same damn thing is going to happen again if they allow this to occur,” he said.