Morgan Stanley CEO John Mack may have buffed his own image as well as his firm’s by advising the U.S. Treasury on the historic bailouts of Fannie Mae and Freddie Mac . But the assignment didn’t come without a cost. In July, when Treasury Secretary Hank Paulson phoned Mack and asked for his help on assessing what do do with the reeling mortgage-loan giants, Morgan was set to receive at least $20 million in fees from Freddie for helping to raise billions of dollars in capital. The firm was also lining up potential advisory work for Fannie, which could have inflated Morgan’s total take to some $40 million.

“We had a whole team working with Freddie,” recalls Mack, in his first interview about the government’s Fannie-Freddie rescue plan. “I told [the bankers assigned to Freddie]. ‘I appreciate what you’re doing. And I know you need to get paid.’” Morgan Stanley will receive at most $95,000 for its advisory work–the maximum allowed from the government on a pro bono assignment.

Mack ended up assigning two Morgan Stanley veterans to lead the team that worked with Treasury. Vice chairman Bob Scully typically handles Morgan Stanley’s most complicated transactions, including work with KKR and General Motors (for example, the sale of 51% of GMAC to private equity firm Cerberus). Ruth Porat heads Morgan’s financial institutions business. Together, they led a team of 39 executives, employing a divide-and-conquer approach. They assigned teams dedicated to mortgage analytics (to assess Freddie and Fannie’s capital positions and needs), capital markets (to take the pulse of stock- and bond-holders), and regulatory issues. To help with the latter, they recruited law firm Cleary Gottlieb, which worked pro bono as well.

Porat and Scully and their crew of three dozen worked virtually full-time on the project–often 7 a.m. to 11 p.m. in New York and Washington. They spent Labor Day at the Treasury Department offices–with lots of diet Cokes, and Paulson himself popping in at all hours. As the teams realized that the easiest option–Freddie and Fannie raising more capital on their own—was untenable, they considered three others: an equity investment by the government, conservatorship, or receivership, which would likely have lead to Freddie and Fannie’s liquidation.

They fretted about an equity infusion, wondering: What level of capital would be adequate? Would it be the first of many that the government would have to inject? How can the government get control of the businesses and protect taxpayers? Conservatorship, the ultimate solution, provides the needed control—and indeed, the government immediately replaced the managements at both companies. Conservatorship is a “timeout,” as one banker calls it: a temporary takeover that leaves options open for the next administration in Washington.

“It was the right thing to do,” says Mack. Now, as Wall Street reels from trouble both reputational and financial, he contends that Morgan Stanley should do more pro bono work, even as it means giving up fees. “One of the things is—not that we’re not good citizens,” he says.  “But I don’t think we’ve been reaching out enough, to do things like sending young people to Washington to work on energy policy and work with Treasury.” The recent assignment “was a bigger step in that direction–putting our senior stars out there to do pro bono work.”

Meanwhile, Mack is dealing with a low stock price (down 31% in the past 12 months), billions of dollars of writeoffs on soured loans, and questions about whether he has a viable prospect in-house to succeed him as CEO. Last week, the Wall Street Journal speculated that Mack, 64, might be willing to sell Morgan Stanley. He adamantly denies this, noting that he never talked to the Journal about the matter. “I’m not thinking about selling the firm,” he says, adding, “I’m thinking about investing in the firm in a big way.”