Maryland Cup Corp., which has conducted abortive merger talks with several companies during the past few years, said yesterday it finally has agreed to be acquired in a $536 million deal with Fort Howard Paper Co.

But with an eye perhaps to Maryland Cup's failed merger discussions with another unnamed company earlier this month, Fort Howard and Maryland Cup included in their agreement an unusual clause that could be used to ward off a competing offer from another firm by guaranteeing Fort Howard an 18 percent block of Maryland Cup stock.

Although they insisted that the clause was routine, officials of both companies acknowledged that it was included as protection. "The deal was put together as it was for a number of good reasons," said a Fort Howard spokesman. Said Eugene Foreman, Maryland Cup's vice president for finance, "You never know" if a competing offer will be made.

Analysts described the combination of Maryland Cup and Fort Howard as a good fit, combining two companies with similar but not overlapping businesses often serving the same customers.

Maryland Cup, of Owings Mills, makes Sweetheart-brand paper cups--one of its major customers is McDonalds--and a variety of other disposable food containers and plates. Fort Howard, of Green Bay, Wis., makes paper towels, napkins and bathroom tissue, and is the nation's largest producer of tissue for commercial markets. With $656 million in sales and $31.7 million in earnings last year, Maryland Cup is slightly bigger than Fort Howard, which had $537 million in sales and $92.4 million in earnings.

Maryland Cup will become a subsidiary of Fort Howard, and the three members of the company's executive committee will join Fort Howard's board. The proposed merger must be approved by the shareholders of both companies.

Under the terms of the agreement, Fort Howard will pay $52 a share cash for 49 percent of Maryland Cup's 10.5 million shares of stock, and 0.85 share of Fort Howard stock for each remaining share. Fort Howard stock fell $3.375 to $55 yesterday, making the second half of the deal worth $46.75 a share. Maryland Cup sold for $48.25 a share yesterday, up $1.25.

Fort Howard also received the option to buy 1.95 million additional, newly issued Maryland Cup shares for $52 apiece. Such an option is an occasionally used ploy that can frustrate a competing offer by guaranteeing Fort Howard a sizable chunk of Maryland Cup stock.

Fort Howard also has been pledged 22 percent of Maryland Cup stock owned by the founding Shapiro family. The Shapiros own 52 percent of Maryland Cup's stock, and sources said they are expected to offer much of that toward the Fort Howard offer.

Maryland Cup and Fort Howard have talked merger before, with the negotiations breaking down two years ago. But the two companies apparently got back together after Maryland Cup ended talks June 9 with an unnamed foreign suitor. In recent years, Maryland Cup also has had merger talks with Kraft Inc., now Dart & Kraft Inc., and possibly other companies as well.

"They have talked to the whole world in the last 10 or 15 years," said analyst George B. Adler, who follows both companies for Smith Barney Harris Upham. "What you have read in the newspapers is the tip of the iceberg, I'm sure."

Adler speculated that the Shapiro family had decided to sell the company because the generation of family members who have been the top managers of the company is near retirement age and few of the members of the next generation have chosen to enter the family business. In addition, Adler said some of the company's traditional markets such as the fast-food business are maturing, and the company needs a partner for future diversification and expansion.