The subprime-mortgage crisis has been a financial catastrophe for much of Wall Street. At Goldman Sachs Group Inc. thanks to a tiny group of traders, it has generated one of the biggest windfalls the securities industry has seen in years.

The group's big bet that securities backed by risky home loans would fall in value generated nearly $4 billion of profits during the year ended Nov. 30, according to people familiar with the firm's finances. Those gains erased $1.5 billion to $2 billion of mortgage-related losses elsewhere in the firm. On Tuesday, despite a terrible November and some of the worst market conditions in decades, analysts expect Goldman to report record net annual income of more than $11 billion.

Goldman's trading home run was blasted from an obscure corner of the firm's mortgage department -- the structured-products trading group, which now numbers about 16 traders. Two of them, Michael Swenson, 40 years old, and Josh Birnbaum, 35, pushed Goldman to wager that the subprime market was heading for trouble. Their boss, mortgage-department head Dan Sparks, 40, backed them up during heated debates about how much money the firm should risk. This year, the three men are expected to be paid between $5 million and $15 million apiece, people familiar with the matter say.

Under Chief Executive Lloyd Blankfein, Goldman has stood out on Wall Street for its penchant for rolling the dice with its own money. The upside of that approach was obvious in the third quarter: Despite credit-market turmoil, Goldman earned $2.9 billion, its second-best three-month period ever. Mr. Blankfein is set to be paid close to $70 million this year, according to one person familiar with the matter.

Goldman's success at wringing profits out of the subprime fiasco, however, raises questions about how the firm balances its responsibilities to its shareholders and to its clients. Goldman's mortgage department underwrote collateralized debt obligations, or CDOs, complex securities created from pools of subprime mortgages and other debt. When those securities plunged in value this year, Goldman's customers suffered major losses, as did units within Goldman itself, thanks to their CDO holdings. The question now being raised: Why did Goldman continue to peddle CDOs to customers early this year while its own traders were betting that CDO values would fall?

A spokesman for Goldman Sachs declined to comment on the issue.

The structured-products trading group that executed the winning trades isn't involved in selling CDOs minted by Goldman, a task handled by others. Its principal job is to "make a market" for Goldman clients trading various financial instruments tied to mortgage-backed securities. That is, the group handles clients' buy and sell orders, often stepping in on the other side of trades if no other buyer or seller is available.

The group also has another mission: If it spots opportunity, it can trade Goldman's own capital to make a profit. And when it does, it doesn't necessarily have to share such information with clients, who may be making opposite bets. This year, Goldman's traders did a brisk business handling trades for clients who were bullish on the subprime-mortgage-securities market. At the same time, they used Goldman's money to bet that that market would fall.

. Tight Leash

Financial firms have good reason to keep a tight leash on proprietary traders. In 1995, bad bets by Nicholas Leeson, a young trader, led to $1.4 billion in losses and the collapse of Barings PLC. Last year, the hedge fund Amaranth Advisors shut down after a young Canadian trader lost more than $6 billion on natural-gas trades. But big trading wins such as George Soros's 1992 bet against the British pound, which netted more than $1 billion for his hedge fund, tend to be talked about for years.

The subprime trading gains notched by Messrs. Birnbaum and Swenson and their Goldman associates are large by recent Wall Street standards. Traders at Deutsche Bank AG and Morgan Stanley also bet against the subprime-mortgage market this year, but in each case, their gains were essentially wiped out because their firms underestimated how far the markets would fall. New York hedge-fund company Paulson & Co. also turned a considerable profit on the subprime meltdown this year, as did Hayman Capital Partners, a Dallas-based hedge-fund firm, say people familiar with the matter.

As recently as a year ago, few on Wall Street thought that the market for home loans made to risky borrowers, known as subprime mortgages, was heading for disaster. At that point, Goldman was bullish on bonds backed by such loans.

. Hashing Out Risk

Last December, Mr. Sparks, a longtime trader of bond-related products, was named head of Goldman's 400-person mortgage department. That gave him a seat on the firm's risk committee, which numbers about 30 and meets weekly to hash out the firm's risk profile. It also gave him authority over the structured-products trading group, which then had just eight traders and was run jointly by Mr. Swenson and David Lehman, 30, a former Deutsche Bank trader.

Mr. Swenson, known as Swenny on the trading desk, is a former Williams College hockey player with four children and an acid wit. A veteran trader of asset-backed securities, he joined Goldman in 2000. In late 2005, he helped persuade Mr. Birnbaum, a Goldman veteran, to join the group. Mr. Birnbaum had developed and traded a new security tied to mortgage rates.

Mr. Swenson and Mr. Sparks, then No. 2 in the mortgage department, wanted Mr. Birnbaum to try his hand at trading related to the first ABX index, which was scheduled to launch in January 2006. Because securities backed by subprime mortgages trade privately and infrequently, their values are hard to determine. The ABX family of indexes was designed to reflect their values based on instruments called credit-default swaps. These swaps, in essence, are insurance contracts that pay out if the securities backed by subprime mortgages decline in value. Such swaps trade more actively, with their values rising and falling based on market sentiments about subprime default risk.

Messrs. Swenson and Sparks told Mr. Birnbaum the ABX was going to be a hot product, according to people with knowledge of their pitch.

They were right. On the first day of trading, Goldman netted $1 million in trading profits, people familiar with the matter say. But the index was tough to trade. In comparison to huge markets like Treasury bonds, there wasn't much buying and selling. That meant that Mr. Swenson's team nearly always had to use Goldman's capital to complete trades for clients looking to buy or sell.

. Signs of Weakness

Last December, David Viniar, Goldman's chief financial officer, gave the group a big push, suggesting that it adopt a more-bearish posture on the subprime market, according to people familiar with his instructions. During a discussion with Mr. Sparks and others, Mr. Viniar noted that Goldman had big exposure to the subprime mortgage market because of CDOs and other complex securities it was holding, these people say. Emerging signs of weakness in the market, meant that Goldman needed to hedge its bets, the group concluded, these people say.

Mr. Swenson and his traders began shorting certain slices of the ABX, or betting against them, by buying credit-default swaps. At that time, new subprime mortgages still were being pumped out at a rapid clip, and gloom hadn't yet descended on the market. As a result, the swaps were relatively cheap.

Still, trading volume was thin, so it

took months for the group to accumulate enough swaps to fully hedge Goldman's exposure to the subprime market. By February, Goldman had built up a sizable short position, and was poised to profit from the subprime meltdown.

The timing was nearly perfect. Goldman's bets were focused on an ABX index that reflects the value of a basket of securities that came to market in early 2006, known as the 06-2 index. Goldman bet that the riskiest portion of that index -- a sub-index that reflects the value of the slices of the securities with the lowest credit ratings -- would plunge in value. This January, as concerns about subprime mortgages grew, that sub-index dropped from about 95 to below 90. The traders handling the ABX trades were sitting on big profits.

Like other Wall Street firms, Goldman weighs its financial risk by calculating its average daily "value at risk," or VaR. It's meant to be a measure of how much money the firm could lose under adverse market conditions. Because the ABX had become so volatile, the VaR connected to the trades was soaring.

Goldman's co-president, Gary Cohn, who oversees the firm's trading business, became a frequent visitor, as did the firm's risk managers. More than once, Mr. Sparks was summoned to Mr. Blankfein's office to discuss the market. Goldman's top executives understood the group's strategy, say people with knowledge of the matter, but were uncompromising about the VaR. They demanded that risk be cut by as much as 50%, these people say.

Messrs. Swenson and Birnbaum, however, argued that the mortgage market was heading down, and Goldman should take full advantage by maintaining large short positions, people familiar with the matter say.

One day in late February, with the riskiest portion of the 06-2 index heading toward 60, the discussion about what to do grew heated, these people say. Mr. Birnbaum argued that Goldman would be leaving money on the table by unwinding some of the trades his group had used to bet on the mortgage market's decline.

"This is the wrong price" to close out the positions, Mr. Birnbaum snapped at a colleague assigned to help reduce risk, slamming down his phone receiver, these people say. He was overruled.

In March and April, the risky portion of the 06-2 index, which had taken a beating in February, bounced back from near 60 into the mid-70s. By then, the CDO underwriting business, which had been lucrative for Goldman, Merrill Lynch & Co. and other Wall Street firms, was slowing dramatically. Potential buyers had grown worried about the market.

Thanks to the wager that the ABX index would fall, Goldman's mortgage department earned several hundred million dollars during the first quarter, say people familiar with the matter. But the traders had unwound that bet in the weeks that followed. That left Goldman unhedged against further carnage, a worrisome situation for the second quarter.

In late April, Mr. Sparks, the mortgage-department chief, met with Mr. Cohn, the trading head, Mr. Viniar, the chief financial officer, and a couple of other senior executives. "We've got a big problem," Mr. Sparks told them as they paged through a handout listing the declining values of Goldman's CDO portfolio, according to people with knowledge of the meeting. Prices were heading straight down, he told them. He suggested that Goldman cancel a number of pending CDO deals, these people say, and sell whatever it could of the firm's roughly $10 billion in CDOs and related securities -- probably at a loss.

. Into the Red

Led by Mr. Lehman, the co-head of the structured-products trading group, Goldman began selling off the majority of its CDO holdings. The losses pushed the mortgage group into the red for the second quarter.

By then, the subprime-mortgage market was cratering. Dozens of lenders had filed for bankruptcy protection, and legions of subprime borrowers were losing their homes. At Bear Stearns Cos. two internal hedge funds that had invested in risky portions of CDOs and other securities were struggling. Merrill and Citigroup Inc. among others, were sitting on billions of dollars in depreciating mortgage holdings.

Although it had become more expensive to wager against the ABX index, Messrs. Swenson and Birnbaum got a green light to once again ratchet up the firm's bet that securities backed by subprime mortgages would fall further. In July, the riskiest portion of the index plunged.

. No Time for Breaks

The structured-products traders were working long hours. Mr. Swenson would leave his home in northern New Jersey in time to hit the gym and be at his desk by 7:30 a.m. When Mr. Birnbaum arrived from his Manhattan loft, they'd begin executing large trades on behalf of clients. There was no time for breaks. They took breakfast and lunch at their desks -- for Mr. Swenson, the same chicken-and-vegetable salad every day from a nearby deli; for Mr. Birnbaum, an egg-white sandwich for breakfast, a chicken or turkey sandwich for lunch.

Mr. Sparks, the mortgage chief, climbed into his car at 5:30 each morning for the drive in from New Canaan, Conn. To calm his nerves, he'd stop by the gym in Goldman's downtown building to briefly jump rope and lift weights. Sometimes he worked past midnight, arriving home exhausted. He canceled a family ski trip to Wyoming. Although he loved to attend Texas A&M football games and owned a second home near the university, he decided not to join his wife and two children on more than one trip. (Mr. Sparks is a major donor to the university's athletic program.)

By late July, the Bear Stearns funds had collapsed and rumors were circulating of multibillion-dollar CDO losses at Merrill. Goldman was raking in profits.

But once again, concern was growing about VaR, the all-important measure of risk. At one point in July, senior executives called another meeting to demand the mortgage traders pull back, according to people familiar with the matter. The traders agreed.

. Ratcheting Back

Around Labor Day, Mr. Birnbaum was asked to ratchet back one of his short positions by $250 million, according to Hayman Capital managing partner Kyle Bass, a client who had similar positions at the time. Mr. Bass says he made $100 million by relieving Goldman of that particular short bet. "It appeared to me that [the traders] constantly fought a VaR battle with the firm once the market started to break," says Mr. Bass.

In the first three quarters of its fiscal year, Goldman's VaR rose 38%, ending that period at $139 million per day, an all-time high, regulatory filings indicate.

During the third quarter ended Aug. 30, the structured-products trading group made more than $1 billion, say people knowledgeable about its performance. That helped the mortgage department notch record quarterly earnings of $800 million, these people say.

The subprime market continued to deteriorate through the fall. Both Merrill and Citigroup announced massive write-downs connected to the subprime mess, and their chief executive officers resigned.

Goldman pressed forward with its bearish bets on the ABX index, people familiar with its strategy say. In October, Goldman's mortgage unit moved from one downtown Manhattan office building to another. Despite their stellar year, traders were crowded into a low-ceiling floor where 150 employees shared one small men's room.

In late November, Mr. Sparks summoned Messrs. Birnbaum and Swenson to his office for separate visits. He thanked each trader for what he had done for the firm.

But there has been no time to relax. Two weeks into Goldman's new fiscal year, credit markets are looking bleaker than ever. Already, analysts are trimming their estimates of how much Goldman and other Wall Street firms will make in the coming year.