Treasury Secretary Timothy F. Geithner stood before staff members at a recent town hall meeting and offered a eulogy for the government's $700 billion bank bailout program, which is set to expire Sunday, two turbulent years after Congress approved it during the heat of the financial crisis.

He understood as well as anyone the paradox that the Troubled Assets Relief Program, or TARP, has come to represent: Economists largely agree that the massive federal bailouts beginning in 2008 saved the country from a financial abyss. But rarely has a government program become so widely reviled, so stigmatized, that even lawmakers who voted for it avoid the subject.

Geithner noted that TARP had been called un-American, a deliberate departure from free market principles. He cited the unrelenting outrage from lawmakers who continue to question the program's effectiveness. He acknowledged that most Americans remain "rightfully angry" at seeing their government bail out the financial firms whose recklessness sent the housing market into a tailspin, triggered a wave of unemployment and wreaked havoc on the economy.

And then he offered the full-throated defense of TARP that he and other officials have repeated often in the wake of the financial crisis, an insistence that he and his predecessors made hard but courageous choices.

"It wasn't fair," he said of the bailouts. "But it was necessary."

Indeed, most experts agree that the government's quick and massive bailouts of some of the country's biggest financial firms and automakers - from Citigroup to General Motors to insurance giant American International Group - prevented a far worse outcome.

"While the TARP has not been a universal success, it has been instrumental in stabilizing the financial system and ending the recession," economists Alan Blinder and Mark Zandi co-wrote in a recent paper. Without it, "the entire system might have come to a grinding halt."

Despite initial fears that taxpayers could lose hundreds of billions of dollars, the estimated cost of TARP has decreased steadily as banks have repaid bailout money and as the Treasury has received interest and dividend payments on its investments and sold stakes in companies it helped rescue. In a recent report, the Congressional Budget Office projected the lifetime cost of the program at $66 billion, a number that could continue to fall if certain efforts, such as a plan for AIG to repay its taxpayer aid, unfold successfully.

But it hasn't been all roses and high-fives.

For starters, TARP represented only a fraction of what the government spent to save the financial system. The Treasury and the Federal Reserve alone have committed more than $1.5 trillion to prop up the faltering mortgage and housing markets.

The bailouts left the federal government deeply involved in the private sector, an unprecedented and uncomfortable marriage that has stoked anger and resentment on all sides.

TARP's detractors - even watchdogs overseeing it - have criticized officials for poor management, a lack of transparency, and even for altering the original approach of buying troubled assets. They also note the program's glaring failure in combating foreclosures.

By every measure, TARP remains hated by a public that views it as little more than a rescue of the rich Wall Street titans who caused the crisis. Most of those firms have rebounded, but the benefits are far less tangible for millions of unemployed workers and homeowners behind on their mortgage payments.

That deep-seated resentment has factored into the anti-Washington, anti-incumbent sentiment so prominent in this year's midterm elections, in which a yes vote on TARP has proven to be its own toxic asset.

Veteran Sen. Robert F. Bennett (R-Utah), who lost his bid for reelection in a May primary, was met with chants of "TARP, TARP, TARP'' during one of his speeches at a party convention. Sen. Blanche Lincoln (D-Ark.) narrowly survived a primary challenge from an opponent who dubbed her "Bailout Blanche."

When policymakers created TARP on the fly in September 2008, Geithner said, "the world was falling apart around us."

The House initially rejected the measure, only to see the Dow industrial average plunge to its largest single-day drop ever. The Senate approved the bailout fund on Oct. 1, 2008, and the House quickly followed suit, with 91 Republicans joining 172 Democrats to approve the proposal.

Two years later, the program - if not the controversy surrounding it - is winding down. After Sunday, the Treasury no longer will be able to launch initiatives using the money, though some programs will continue to operate for years.

According to the special inspector general overseeing the fund, seven of the 13 aid programs that make up TARP had closed or were winding down as of June 30. Of the $700 billion approved by Congress, the Treasury has handed out less than $400 billion.

"I know across the country Americans will rejoice in its demise," Geithner said. "TARP was something our country should never have had to do. . . . But for all the baggage, there is something to embrace about TARP."

Not that taxpayers are out of the woods. Scores of small banks have failed to repay the aid they received, and the federal government still has tens of billions of dollars tied up in GM, AIG and other companies.

But the biggest cost of TARP might not become clear for years - and it might not involve dollars and cents.

"Unless the programs's effectiveness can be convincingly demonstrated, the government will not authorize similar policy responses in the future," members of the bipartisan Congressional Oversight Panel wrote in their most recent report. "Thus, the greatest consequence of the TARP may be that the government has lost some of its ability to respond to financial crises."