Federated Department Stores Inc., having vigorously fought Canadian real estate developer Robert Campeau's takeover attempts for more than two months, finally relented yesterday and agreed to a $6.6 billion takeover by Campeau.

The largest non-oil merger in corporate history will bring about a major realignment of American retailers as some of the biggest stars in the business -- such Federated chains as Bloomingdale's, Filene's, I. Magnin, Bullock's and Ralph's supermarkets -- get divided up among other major retailers.

At the same time, it gives Campeau -- who acquired and dismembered much of Allied Stores Corp. in late 1986 -- a much larger stake in the retailing business and access to some of the most desirable real estate in shopping centers across the country.

Even so, the acquisition does not leave Campeau's chief rival in the takeover battle, R.H. Macy & Co., empty-handed.

Macy's -- which earlier had reached a friendly takeover agreement with Federated's board -- walks away with two of Federated's prize possessions: the 20-store Bullock's/Bullocks Wilshire chain in southern California and the 25-store specialty apparel chain I. Magnin. Macy's will pay Campeau $1.1 billion for the chains. Meanwhile, Federated will pay Macy's $60 million for the legal expenses the New York-based retailer incurred during the takeover battle.

"Everybody comes out happy here, which is unusual," said Harry S. Mortner, a financial analyst with Cyrus J. Lawrence Inc.

Campeau gets the company he has hotly pursued since late January, when he launched a $47-per-share bid for Federated. As a result of the furious bidding war he touched off, Federated shareholders will receive $73.50 in cash for each of their shares -- a 56 percent increase over the initial bid and double the price of Federated shares since the stock market crash in October. "Shareholders should be delighted," Mortner said.

"It's great for Macy's as well, because it will now be in southern California -- something it has always wanted," Mortner added. Macy's already has extensive operations in northern California.

Other department-store chains also will benefit, under previous agreements made with Campeau. May Department Stores -- which owns Hecht Co. and many other department-store chains -- has agreed to buy Federated's Massachusetts-based Filene's and Texas-based Foley's chains from Campeau for a total of $1.5 billion, to help Campeau reduce some of the debt he will incur in taking over Federated. That agreement also eliminates potential antitrust problems in Boston, where Filene's and Jordan Marsh -- an Allied Stores subsidiary -- vigorously compete.

In addition, Britain's Marks & Spencer PLC will get a long-sought foothold in the American market through an earlier agreement with Campeau to buy Allied's Brooks Brothers chain for $770 million if Campeau succeeded in buying Federated.

The deal is also a major victory for Campeau's adviser, the new investment banking firm Wasserstein, Perella & Co., which was formed several weeks ago when noted deal makers Bruce Wasserstein and Joseph Perella left First Boston Inc. to start their own firm.

Yesterday's agreement ends the bitter two-month battle for Federated and came after three days of intense negotiations among Federated, Macy's and Campeau officials.

Fearful that a Campeau takeover would lead to a complete breakup of the company, Federated sought to ward off the Canadian developer by signing a merger agreement with Macy's in early March.

But Campeau raised his bid and sued to block the agreement, only to be countered by a higher bid from Macy's and rebuffs in the courts.

Finally, last week, Campeau raised his bid again -- at which time Federated's board decided to put the company up for auction, asking both Macy's and Campeau to make their best offers.

Retailing officials said support among Federated's management for Macy's offer waned after Macy's Chairman Edward S. Finkelstein indicated that he planned to close Federated's Cincinnati headquarters after the merger was completed. At that point, retailing executives said, the criterion for the decision became simply price.

The two contenders exchanged a flurry of bids this week, constantly changing the price and terms of their offers. At one point, the two bids were separated by just 12 cents a share.

A source close to Macy's said that although the chain had the financing to top Campeau's final bid, it declined to because it felt "it didn't make economic sense."

Macy's Finkelstein was not disappointed, however. "We are very pleased with this result and believe we have made a prudent decision," he said. "We are especially pleased with {acquisition of Bullock's and I. Magnin} since they are two of the Federated divisions in which we were most interested."

Retailing officials expect Campeau will be forced to sell many of Federated's assets to help reduce the massive debt from the deal -- much as he did after he bought Allied Stores. Campeau sold 16 divisions of Allied, including the local Garfinckel's chain.

But Allied President Robert Morosky said last night that Campeau would sell only the specialty chains such as Ralph's and Gold Circle and the department stores Campeau already had agreed to sell. "I can't afford to sell many of the other divisions because it would trigger taxes and the price is already so high," Morosky said. He added that although many of the operations of the two chains would be combined, Federated's name and Cincinnati headquarters would be retained.

Financial analysts predicted yesterday that the takeover would increase competition in the retailing industry. "At this high price level, we'll see a more exciting department-store environment, as companies become more aggressively competitive to lower the high level of debt behind them," said Thomas H. Tashjian, a financial analyst with Seidler Amdec Securities Inc. "We'll see a greater attempt to differentiate and more aggressive marketing."

Even so, "a lot of retailers will breathe easier as well," said Kurt Barnard, publisher of the Retail Marketing Report. "If Macy's and Federated got together, it is a foregone conclusion they would have achieved enormous economies of scale and buying power that would have placed competitors at a disadvantage."

But with Federated being divided among a host of retailers, he said, "we will see a refreshing new edge appear in the marketplace."