Boeing Co. yesterday agreed to buy the defense and space divisions of Rockwell International Corp. for $3.2 billion, in a continuation of the aerospace industry's consolidation into fewer but larger players.

The transaction further commits Boeing, the world's largest manufacturer of commercial jetliners, to its relatively modest military and space businesses. It also allows the Seattle-based company to compete more effectively with Lockheed Martin Corp. of Bethesda, the biggest player in those fields, especially in work for the National Aeronautics and Space Administration.

Rockwell has been trying to sell its defense and space divisions for more than a year so it can concentrate on its four other businesses, which are growing faster than defense -- industrial automation equipment, computer chips for fax modems, commercial avionics and communications, and automotive components.

Several other industry players also had considered buying pieces of Rockwell lately, including McDonnell Douglas Corp., whose executives declined comment yesterday. But other industry officials speculated that a two-month strike by McDonnell machinists set back those talks, along with Rockwell's insistence on a number of complex tax gambits in connection with any sale.

As part of the deal, Boeing will give Rockwell shareholders about $860 million in stock and assume about an estimated $2.3 billion in Rockwell debt and pension fund liabilities. Industry officials said the transaction is likely to pass muster with antitrust regulators.

Wall Street analysts have said for years that Rockwell's aerospace business was dragging down its stock price. Several welcomed yesterday's announcement.

"It's a great fit and a good deal for both companies," said Jon Kutler, president of Quarterdeck Investment Partners, an investment banker specializing in the aerospace industry.

Until now, Boeing had sat on the edge of the defense industry dance floor as more and more competitors paired off in mergers. "They see now they may not have another opportunity to make this kind of large buy" if they wait any longer, Kutler said. The aerospace industry is undergoing another spurt of merger mania, he said.

St. Louis-based McDonnell Douglas, for example, is discussing a deal to buy Raytheon Co.'s defense operations, industry officials said. That follows other reports in the last year that McDonnell Douglas had considered buying Rockwell's defense operations or merging with Boeing.

In April, Lockheed Martin bought the defense businesses of Loral Corp. for $9.7 billion, only a year after its own creation through the $10 billion merger of Lockheed Corp. and Martin Marietta Corp.

A few years ago, some analysts speculated that Boeing would sell its defense and space operations. But Boeing executives decided that the new technologies and manufacturing processes that it masters in doing government work can be valuable when applied to building planes such as its newest jetliner, the 777, as well as to its eventual development of a next-generation super-large aircraft. Recently, Boeing reestablished its commitment to defense work by bidding against McDonnell Douglas and Lockheed Martin to develop a new military jet called the Joint Strike Fighter.

If Loral's businesses are counted, Lockheed Martin had 1995 revenue of $29 billion, with the vast majority coming from work for the Pentagon or NASA -- and 1996 sales are expected to be in approximately the same range. By contrast, the combination of Boeing and Rockwell's space and defense businesses is expected to have 1996 revenue of about $25 billion -- though only about $9 billion, or 36 percent, comes from NASA and military work.

Some industry officials said this purchase comes at an inconvenient time for Boeing's top managers, whose attention has been diverted by several other events lately. Their once-underworked factories are suddenly scrambling to fill new airliner orders, even as the company is carrying out an initiative to cut costs and computerize aircraft design operations. THE BOEING-ROCKWELL DEAL

In a $3.2 billion deal, Boeing agreed to acquire much of Rockwell International's aerospace and defense business. A look at where the deal leaves the two companies. Boeing in Brief Business: Commercial jetliners as well as space projects and combat aircraft. Chief executive: Phil Condit Headquarters: Seattle Employees: 105,000 Key divisions: Commercial transport; defense and space products. 1995 profit: $393 milion 1995 revenue: $19.5 billion What Boeing Got From Rockwell Space systems Revenue: $1.88 billion Employees: 12,000 Key products: Space shuttle, space station, global positioning satellites. Defense electronics Revenue: $987 million Employees: 6,000 Key products: Hellfire and AGM-130 missiles, military communications. Aircraft Revenue: $565 million Employees: 3,000 Key product: B-1 bomber, commercial jetliner components. What Rockwell Kept Automation Revenue: $4 billion Key products: Equipment and software used in industrial automation. Semiconductor systems Revenue: $1 billion Key products: Computer chips for fax modems. Collins Avionics, Communications Revenue: $1.4 billion Key products: Navigation and communication products for aviation industry, trucks and railroads. Automotive Revenue: $3 billion Key products: Components for light and heavy vehicles. Revenue by division Defense, space: $5.8 billion Commercial aircraft: $13.7 billion SOURCES: Boeing, Rockwell, Bloomberg Business News