A group led by Sony Corp. yesterday agreed to buy Metro-Goldwyn-Mayer Inc. for $2.9 billion, after Time Warner Inc. dropped out of the bidding for the venerable Hollywood studio.

Known for the roaring lion that begins its films, MGM has a valuable collection of thousands of motion pictures, including the James Bond and Rocky series, that could be profitably sold on DVDs, on television and through other channels of distribution.

The film library was the primary asset that attracted the attention of Sony, an entertainment conglomerate that includes movie, music and consumer-electronics operations. Sony's partners in the MGM deal include Providence Equity Partners Inc., Texas Pacific Group and DLJ Merchant Banking Partners.

Sony agreed to pay $12 a share in cash for MGM, or more than $2.9 billion, and to take on about $1.9 billion of MGM debt. Time Warner's final offer, before it withdrew from the bidding, was $11 a share, or $2.7 billion, plus the assumption of the debt.

MGM's biggest shareholder, billionaire octogenarian Kirk Kerkorian, would receive more than $1.7 billion in cash from the deal. Kerkorian has bought and sold the company several times over the years, and also walked away from various proposed transactions when he did not get the final price he was seeking.

MGM stock closed yesterday at $11.55, up 44 cents. The stock has traded between $8.83 and $12.96 a share over the past year.

Sony closed at $35.82, up 53 cents. Time Warner stock closed at $16.45, down 6 cents.

MGM said it received a security deposit of $150 million yesterday from Sony in connection with the agreement. Sony officials declined to comment.

Over the weekend, Sony scrambled to outbid Time Warner by seeking partners to help pay for the acquisition. Time Warner made its all-cash offer alone and then pulled out yesterday after learning of Sony's offer.

"As we pledged to our shareholders, we approach every potential acquisition with strict financial discipline," Time Warner chairman and chief executive Richard D. Parsons said in a statement. "Unfortunately, Time Warner could not reach agreement with MGM at a price that would have represented a prudent use of our growing financial capacity. We are confident that there are other capital allocation choices that will enable us to continue to build shareholder value."

Time Warner has been using cash to pay down debt in recent years. The media giant is focusing on other potential acquisitions, including the cable television assets of Adelphia Communications Corp., which has filed for bankruptcy protection. Time Warner recently provided hundreds of millions of dollars in cash to its America Online subsidiary in Dulles to buy Advertising.com.

Jordan Rohan, an analyst with Soundview Technology, said Time Warner was smart to avoid a bidding war. "It is the right thing to do in this environment," he said.

At one point, Time Warner executives explored issuing new shares of stock to pay for some, or all, of MGM. That would potentially have made the deal attractive to Kerkorian, since it would have enabled him to avoid paying capital gains taxes immediately.

But Time Warner backed away from the idea for a number of reasons. The company's executives did not relish the idea of having Kerkorian as a large shareholder, according to people familiar with the MGM deal.

Also, the media behemoth and its America Online subsidiary remain the subject of an ongoing Securities and Exchange Commission probe into bookkeeping practices. With the SEC refusing to approve the registration of new Time Warner shares until that investigation is resolved, the company's ability to issue new shares of stock was constrained.

Philadelphia-based Comcast Corp., the nation's largest cable television operator, confirmed that the company may join the Sony investor group. In addition, Comcast confirmed that it has entered into an agreement with Sony that would allow it to market movies from Sony Pictures and MGM to its cable subscribers and also would create new cable channels for Sony and MGM movies.

MGM has about 4,000 motion pictures and 10,400 television episodes in its library. MGM, which owns United Artists Corp. and Orion Pictures Corp., said it would recommend the deal to its board for approval in the next two weeks.