Morgan Stanley agreed Monday to pay $54 million to settle the U.S. Equal Employment Opportunity Commission's claim that the Wall Street giant systematically underpaid and failed to promote women.

The eleventh-hour deal, which came after a jury already had been picked, calls for Morgan Stanley to pay $12 million to Allison Schieffelin, the Wall Street trader whose 1998 complaint sparked the case. The firm also has set aside $40 million to pay claims from any of the estimated 340 mid- and upper-level women who are also covered by the settlement who can demonstrate that they were discriminated against.

Morgan Stanley continues to deny that it practiced discrimination, but the firm also agreed to pay $2 million to improve diversity training and to create other internal programs designed to prevent and address discrimination, according to the 19-page settlement document.

"The consent decree is a watershed in safeguarding and protecting the rights of women on Wall Street," said U.S. District Judge Richard M. Berman as he approved the deal. "It focuses . . . on furthering a culture of respect for women at Morgan Stanley."

The settlement prevented a trial that would have spotlighted Wall Street's continuing difficulties with integrating women into a sometimes crude and overwhelmingly male environment. Up to 20 current and former Morgan Stanley employees were expected to testify about how they were denied raises and promotions and exposed to sexist behavior, including all-male outings to strip clubs, hostile comments and a cake shaped like a breast.

The case differs in several key respects from two earlier multimillion-dollar settlements with Wall Street firms: Smith Barney -- now part of Citigroup Inc. -- and Merrill Lynch & Co Inc. The Smith Barney case focused on claims of sexist behavior -- known in the law as a "hostile work environment" -- rather than on claims of discrimination in pay and promotion. Both earlier cases were private, class-action lawsuits without the backing of federal regulators. The two together have paid more than $100 million to resolve complaints through mediation.

The Morgan Stanley case also involved much higher-level women. The women included in the EEOC's case were all in the four top-ranking job categories in the department that oversees trading for large clients such as mutual funds. Some of the plaintiffs made millions a year.

"We hope this sends a message to other employers on Wall Street to take discrimination complaints very seriously," said Elizabeth Grossman, the EEOC supervising trial attorney in charge of the case. "Discrimination is very much a problem on Wall Street."

Morgan Stanley's lead trial attorney Emily Nicklin said the firm settled after a weekend of feverish negotiations because "people make judgments about what is useful for society and themselves."

"We expect this is going to result in a balanced and fair claims process," Nicklin said. "Diversity can always be enhanced."

Under the settlement, the women on whose behalf the EEOC filed suit do not automatically qualify for a cash payout. Instead, each one would have to make a formal claim that includes evidence of discrimination. A retired federal appeals judge, Abner Mikva of the District, has been appointed to weigh those claims and decide whether they are valid and how much money each woman should be awarded.

If there is money left over, Morgan Stanley would use it to fund scholarships for women interested in working in financial services, said Morgan Stanley general counsel Donald G. Kempf Jr.

The consent decree, which will stay in effect for three years, also calls for Morgan Stanley to name an internal ombudsman to act as a point person on sex discrimination issues and an external monitor to review the company's adherence to the settlement and progress at preventing discrimination.

"What's significant [about the settlement] is not only the magnitude of $54 million but also the three-year commitment that Morgan Stanley has made to scrutinize their practices and policies, rather than just writing a check," said Pearl Zuchlewski, a New York employment lawyer who represents financial services professionals.

The EEOC's settlement with Morgan Stanley is the second-largest involving sex discrimination that the agency has ever negotiated. The supermarket chain Publix signed an $81.5 million deal in 1997. Mitsubishi Motors paid $34 million in 1998 to settle the largest sexual harassment complaint.

Morgan Stanley and the EEOC have being trying to settle this case for several years. Berman twice insisted that both EEOC chief executive Cari M. Dominguez and Morgan Stanley chairman Philip J. Purcell appear personally, as he, too, sought a negotiated resolution. But it was not until after eight women and four men were picked for the jury and opening arguments were scheduled for Monday that the participants found common ground. Both Dominguez and Purcell were involved in the negotiations over the weekend, Berman said.

"We are pleased that Morgan Stanley worked cooperatively with us to resolve this litigation," Dominguez said in a news release issued jointly with the investment firm. "With this settlement, Morgan Stanley has taken an important leadership step in adopting progressive programs to promote diversity that should serve as a model for the financial services industry."

And Purcell said in the same release, "We are proud of our commitment to diversity, and would like to thank the EEOC staff for working with us to conclude this matter in such a positive way." About 48 percent of Morgan Stanley's U.S. employees are female, as are 35 percent of "officials and managers."

After Berman announced that he had approved the settlement, a beaming Schieffelin, who was fired by Morgan Stanley in 2000, hugged her mother and nearly a dozen supporters. She then stood outside in the rain to give a brief statement. "I am so happy that there is a settlement agreement that is good for everybody," said the trader, who made about $1.35 million the year she filed her complaint.

Morgan Stanley counsel Donald Kempf is questioned by a CNBC reporter as he arrives at court. The settlement came after jurors had been chosen.