Robert Caplin for The New York Times

It was the deal that helped sink Lehman Brothers. Now, it will play an important role in paying off the failed investment bank’s creditors.

The Lehman estate agreed on Monday to sell Archstone, a sprawling apartment complex company, to its two biggest real estate rivals — Equity Residential, a company run by the investor Samuel Zell, and AvalonBay Communities — for about $6.5 billion in cash and stock.

The sale will dispose of the Lehman estate’s single biggest asset as it continues efforts to wind itself down and pay off the firm’s legions of creditors. And it will end the estate’s plans to take Archstone public, which had been expected to raise $3.45 billion in an offering on the New York Stock Exchange.

While the acquisition of Archstone by Lehman came just as the housing market was slipping from its lofty peak, its sale follows a recovery from the market’s lows. Residential apartment values have surpassed their 2007 peak, and occupancy rates are strong. Still, the market for rental apartments has taken a breather.

Even with the collapse of its Wall Street parent, Archstone has been held in high regard among investors and analysts for the high quality of its properties and the abilities of its management team. The company, based in Englewood, Colo., owns or has a stake in 181 developments with 57,948 apartment units, as of Sept. 30. Its apartments are largely in metropolitan areas in the Northeast, California and southeast Florida.

“Archstone is a highly sophisticated and very well thought-of manager of apartment assets,” said Craig Leupold, the president of Green Street Advisors, a research firm. “If it’s not the highest-quality portfolio around, it’s certainly up there.”

More than four years ago, it was a millstone around the neck of a foundering Lehman. In 2007, the Wall Street firm teamed up with Tishman Speyer to buy Archstone for more than $23 billion, having triumphed in a contest for one of the nation’s premier apartment landlords. The deal was led by Mark Walsh, then Lehman’s head of real estate and considered one of the smartest investors on Wall Street, fond of complex transactions that yielded big profits.

But it meant taking on huge amounts of debt as the housing boom was showing signs of deflating, leaving Lehman significantly weakened as the market turmoil was escalating in 2008. Lehman filed for bankruptcy on Sept. 15 of that year.

During the bankruptcy and as Lehman emerged with a liquidation plan earlier this year, Archstone was identified as an asset that could yield a significant payday for creditors. Even as the Lehman estate sold off other high-quality holdings, including the asset manager Neuberger Berman, it held onto Archstone. It also sold off about $3.6 billion worth of lower-quality assets from the Archstone business.

The stock component of the transaction announced on Monday will give make the Lehman estate the single biggest investor in Equity Residential, with a 9.8 percent stake, and in AvalonBay, with a 13.2 percent stake.

The business attracted suitors, and one of the most persistent was Equity Residential, which had long followed the path set by Mr. Zell: serial deal-making that made it one of the biggest apartment investors in the country.

Another was AvalonBay, an apartment company known for developing properties rather than buying them.

Both companies began talking to the Lehman estate as far back as the summer of 2011, though the talks were in fits and starts, according to people with direct knowledge of the process.

Among the primary concerns within the Lehman real estate team was fetching the highest possible value for Archstone. And that meant buying out the other partners in Archstone: Bank of America and Barclays.

Lehman spent about $2.88 billion to acquire their stakes earlier this year to simplify matters for any new owner.

Yet at the same time, the estate also began an initial offering process for Archstone in case the sales talks broke down. An I.P.O. would have been one of the biggest staged this year, trailing only the likes of Facebook.

In recent weeks, talks between Lehman and the real estate investors picked up steam, these people said. The partnering of Equity Residential and AvalonBay proved especially reassuring, as it reduced the risks that either company would have taken on.

So while Lehman periodically updated Archstone’s offering documents — the most recent update was filed with regulators just last week — teams worked around the clock to secure a transaction.

The Lehman team finally breathed a sigh of relief when most of the major legal paperwork was signed around 1:30 a.m. on Monday.

Under the terms of the deal, Equity Residential and AvalonBay will pay $2.685 billion in cash and about $3.8 billion in stock. That represents a roughly 17 percent premium to what Lehman had valued the company earlier this year. The two companies will also assume Archstone’s roughly $9.5 billion in debt.

Equity Residential, which is run by Mr. Zell, will own about 60 percent of Archstone’s assets and liabilities. AvalonBay will own the remainder.

In return, the Lehman estate will become the single biggest shareholder in each company, holding a 9.8 percent stake in Equity Residential and a 13.2 percent stake in AvalonBay.

“The sale of Archstone to Equity Residential and Avalon Bay is a very positive outcome for our creditors,” Owen Thomas, the chairman of Lehman’s board of directors, said in a statement.

But the Lehman real estate team’s work is not finished: the estate still owns several major properties in New York City and on the West Coast that must be sold.