On a crisp day last October, the prime minister of Greece, George Papandreou, strode along a red carpet into an emergency summit of European leaders in Brussels and boasted to reporters of his government’s “superhuman” response to its debt crisis.

But in the private reports flowing from Athens, the International Monetary Fund’s point person for Greece, Poul Thom­sen, could see a different reality unfolding.

Greece was stiffing government contractors as a way to make its books look better, one set of data revealed. Other figures showed that the government was financing its daily operations with debt, like a family paying for food with a home-equity loan. And Greece was making only halting progress in fulfilling its pledges to reduce public payrolls, shut down money-losing state-owned companies and enforce tax laws.

Greece had made a long list of promises in return for emergency help from the IMF and from other European countries, but agency officials increasingly felt they were being taken for a ride. Having extended the country record amounts of money, the agency was in so deep that it could not just walk away. Nor could it continue pouring good money after bad.

Over the decades since its creation after World War II, the IMF has taken responsibility for ensuring the health of the global economy. The agency has repeatedly rescued teetering governments and restored confidence to panicked markets by coupling its unrivaled expertise with money provided by member countries, most prominently the United States.

But the debt crisis roiling Europe — and threatening to snuff out the U.S. economic recovery — has challenged the IMF like no previous upheaval. By last fall, with the Greek debt disease spreading to larger European countries, there was a real risk that the world economy no longer had an effective backstop.

The worsening situation in Greece recalled the IMF’s traumatic experience a decade earlier with a major assistance program for the government of Argentina. After that effort collapsed, the agency’s internal auditors found that the program had continued well after it became clear that Argentine authorities were not living up to the agency’s conditions and had taken “multiple policy initiatives that the IMF viewed as misguided but felt compelled to endorse.” Argentina had continued to receive loan installments based on political considerations, not economic ones, the auditors concluded.

The prime lesson was that in future rescue programs, the IMF should have a clear strategy for exiting if local officials refused to deliver on promised reforms.

This story, based on interviews with more than 20 principal officials from inside and outside the IMF, is an account of how the agency once again became entangled in a failing rescue effort. It is also the story of how the agency, under the stewardship of its new chief, Christine Lagarde, eventually reasserted control with a tougher line toward Greece and increasingly hard-nosed diplomacy with other European governments.

The result of this fundamental shift at the IMF was reflected in the new Greek bailout approved last month by European leaders. The initiative is more demanding of Greece and other European countries, less generous with IMF money, and far more candid about the likelihood of failure.

Along the way, the agency has pushed Greece to the brink of default, and its demands have triggered violent riots that left downtown Athens ablaze. Now the IMF is trying to salvage the Greek rescue effort, which could prove crucial for the future of the agency, the survival of the euro currency union and the health of the world economy.

A doomed initial rescue

A 30-year veteran of the IMF, Thomsen built a career dispensing the medicine of fiscal and economic reform across Europe’s eastern flank. Overseeing the Greek mission, however, would prove as tricky as anything he confronted in the war zones of the former Yugoslavia or Russia’s crumbling empire. Still, the lanky Dane was confident that his team could succeed despite the ambitious — even unrealistic — assumptions used to assemble the IMF’s initial Greek assistance program in the spring of 2010.

That program would become something of a trap for the agency.

IMF assistance typically comes with many strings attached. The IMF requires a recipient of aid to meet a set of often strict conditions that, at least in theory, are meant to help put the country’s finances on a sounder footing so it can stand on its own again, ultimately allowing the agency to withdraw.

But in the case of Greece, the IMF couldn’t simply require what it thought was best. The agency had to negotiate the terms of the assistance — not only with the government in Athens but also with influential countries and institutions in Europe that had their own parochial interests. The result was a rescue program shaped as much by European politics as by considered calculations about Greece’s economic plight and its capacity for carrying out reforms.

The IMF, which often acts independently, was yoked into a “troika” arrangement alongside the European Central Bank and the European Commission, the executive arm of the European Union. They both wanted an equal say in any IMF rescue effort for Greece.

The ECB, for instance, strongly objected to reducing Greece’s debt burden by making investors in Greek bonds take losses. This took a crucial tool, at least initially, out of the hands of the IMF.

Germany, Europe’s strongest economy and an influential voice at both the ECB and the commission, had its own agenda. Berlin was worried that German taxpayers would end up paying for much of the bailout and pressed to keep lending minimal. Instead, Germany pushed Greece to slash its public spending, though these stiff austerity measures contributed to a deep recession in Greece that made it even harder for the nation to recover.

The program launched in 2010 embodied all those demands. To make the math work, the IMF had to assume that Greece would quickly achieve budget surpluses that far exceeded what the country had ever accomplished, even in the best of times.

The IMF was on the hook for about $35 billion — about a quarter of the total bailout given to Greece — but stuck with a rescue program destined to fail.

Greece’s growing threat

Inside the IMF, Thomsen and others had their eyes open to the risks. But Dominique Strauss-Kahn, the agency’s chief until he was replaced by Lagarde last June, felt strongly that the IMF could not stay on the sidelines. He feared that Europe’s problems posed the top threat to the global economy.

Evidence quickly began to mount that the Greek rescue was running off the rails. But for more than a year, the IMF continued to trumpet it as a success.

At a meeting of European finance ministers in Luxembourg last June, IMF officials urged that Greece be given more money and more time to recover, but European leaders shot down the suggestions because of the concerns of several E.U. member countries. Undaunted, John Lipsky, then the IMF’s deputy managing director, emerged from the meeting and announced that he was “very hopeful” about Greece.

During an IMF review of Greece’s progress a month later, Thomsen acknowledged that aspects of the rescue program needed “reinvigorating,” referring to the government’s snail’s pace in privatizing state-owned companies and liberalizing labor markets to help stimulate the economy. But his overall assessment was that Greece had done “most of what the authorities set out to do.”

By late summer, however, the world was looking at the prospect of a major financial meltdown in the heart of Europe, as the debt crisis that started in Greece now threatened to bankrupt the far larger economies of Italy and Spain. Global stock markets were swooning.

There was a heightened urgency to fix Greece.

But the prognosis for the bailout was getting grimmer. At the IMF, assumptions about Greece’s prospects were tumbling. Spending cuts by the Athens government were weakening economic activity, pushing the country into a deeper recession than expected. The wider European economy was slowing, denying Greece the lift anticipated from trading with its neighbors. And local politicians were failing to follow through with promises of economic reform.

Lagarde gets tough

Behind the scenes, IMF officials were losing patience. They increasingly debated how they could reassert control.

Gradually, officials racheted up the level of public candor about Greece and the euro zone.

In part, this new assertiveness reflected changes ushered in by Lagarde, France’s former finance minister.

Strauss-Kahn, who resigned after his arrest in New York on charges of sexual assault, had emphasized compromise with Europe’s political leaders. His departure made room for dissent from top staff and board members.

Lagarde told top staffers that she had no preconceptions about how to address the European crisis — though she had played an active role in it in France — and invited their arguments about what to do. In her initial days in office, she spent hours closeted with staff members, coming to grips with Greece.

Lagarde also brought in a new second-in-command to the IMF, by tradition a position held by an American. The Obama administration, which was critical in helping Lagarde get her job, tapped National Security Council economic adviser David Lipton. He shared Treasury Secretary Timothy F. Geithner’s view that the IMF should put its efforts into preventing the Greek contagion from spreading to other European countries and the world beyond, and Lipton pressed those arguments inside the IMF.

Lipton was much warier of the IMF getting entangled in large lending programs for individual countries such as Greece. He was known for the hard line he took toward South Korea during its financial meltdown in the 1990s, and he urged after the Asian financial crisis that “the genie of large IMF lending operations” be put “back into the bottle.”

As the Greek economy continued to decay, Lagarde made her influence felt inside the agency. She refereed a sometimes intense debate about how to proceed. Ideas that had been excluded earlier were back on the table.

One such proposal would make investors in Greek bonds take losses, thus reducing Greece’s debts, even if this would weaken the European banks that owned the bonds. Egyptian-born Nemat Shafik, a deputy managing director, arrived from the United Kingdom’s development agency and the World Bank, and argued that Greece was broke and needed an extensive writedown of the value of its bonds.

Earlier, the IMF’s Europe director, Antonio Borges, had resisted this kind of debt restructuring on the grounds that it would damage the credibility of Europe as a whole with global investors. Lagarde would replace him with Reza Moghadam, who argued for a tougher fund stand toward Greece and Europe in general.

As the months passed, Lagarde became more assertive in public as well. In August, she riled Europe’s leaders with a speech warning that the debt crisis was putting the region’s banks at greater risk than many in Europe were willing to admit.

Results come quickly

The turning point came in early October. Lagarde, in an intense round of shuttle diplomacy, visited key European capitals and put leaders on notice that the agency would no longer sugarcoat Greece’s situation.

The IMF, which was preparing a damning analysis, was under no little pressure from its troika partners. Some leaders of the European Commission, according to officials involved in the discussions, were pushing the agency to portray the situation in the most positive light. The ECB worried that the fund would force deeper losses on private investors, including European banks.

But, officials familiar with the talks said, Lagarde found support from the European leader who mattered most, German Chancellor Angela Merkel, who was also tiring of the slow progress in Greece and was under pressure from the White House, financial markets and others to do more.

Back in Washington, La­garde huddled with IMF staff members for several days, refining a wonky-sounding but influential document known as a debt sustainability analysis. Such a report, central to shaping the IMF’s work, analyzes whether a country can over the long term support the government debt it has accumulated, given expected levels of economic growth and public spending.

This time, the IMF didn’t mince words. Nearly two years of austerity by the Greek government had failed to resolve the crisis, the agency reported, and Greece’s debts were on course to spiral out of control. For the IMF to stay involved, the books would have to balance. And for that, the IMF said three things had to happen: European governments had to put more of their taxpayers’ money at risk through larger loans, private bondholders would have to suffer huge losses, and Greece’s politicians would have to live up to their long-standing promises or face default.

The results came rapidly.

Merkel, backed by Lagarde, hauled a representative of Europe’s major banks into a private meeting and dictated that they accept a 50 percent cut in the value of their Greek bonds. European banks were told to prepare for the worst by raising tens of billions of dollars in additional money as a buffer against possible losses, an approach championed by U.S. officials and Lagarde. After losing the confidence of other European leaders, Papandreou resigned as Greek prime minister.

A rescue’s reality check

The IMF’s pressure on Greece continued to mount from there. As negotiations over the new bailout dragged on during the winter, the agency insisted that there would be no more help until Greece carried out its long-promised reforms.

Greek politicians had avoided some of the most wrenching steps designed to liberalize the economy and make it more more competitive. The IMF was demanding immediate action, such as removing protections for traditionally coddled professions and occupations, among them lawyers, doctors and taxi drivers.

The agency had also drawn a line regarding its lending to Greece. The new rescue program approved last month is being financed almost solely with new loans from Europe and with the savings realized in having private investors take losses on Greek bonds. IMF officials say they plan to limit their exposure to Greece to the $35 billion they pledged in the initial bailout. Only as Greece pays back money it owes the IMF will the agency be willing to lend it more.

Even as European leaders and global investors cheered the new bailout, the IMF offered a reality check. In an analysis prepared on the eve of the European summit that approved the rescue effort, the agency warned that Greece might need “prolonged” financial help well beyond the three years envisioned in the new bailout and that Greece’s worsening recession could put the entire effort in jeopardy.

After two years of grinding work in Greece, the IMF grimly concluded: “Given the risks, the Greek program may thus remain accident-prone.”