GAF Corp. yesterday abandoned its fight to gain control of the giant Union Carbide Corp., ending a fierce Wall Street battle that triggered a radical restructuring of Carbide and created hundreds of millions of dollars in profits for shareholders in both companies.

Blocked by an unexpectedly tenacious defense by Carbide management, GAF Corp. Chairman Samuel J. Heyman said it was simply "too expensive" for him to continue his fight for the nation's third-largest chemical company. He nevertheless declared victory, saying that GAF had experienced a $200 million gain from its Carbide stock purchases, including at least $81 million in already realized after-tax profits during the first quarter of 1986.

"I don't view this as a beauty contest or a prize fight," said Heyman in a telephone interview. "This was an economic transaction, and we did very well. . . . In these kinds of contests, you can't let your ego carry you away. I have no complaints as to the ultimate result."

A maverick 47-year-old Connecticut businessman who made a fortune developing shopping malls, Heyman had relished the chance to take over Carbide and assume the helm of a $9.5 billion-a-year company more than 10 times the size of GAF, according to financial analysts.

While being outmaneuvered by Carbide management was undoubtedly a personal blow to Heyman, "he's probably crying all the way to the bank," said Thomas Au, a GAF analyst with Value Line Inc.

Moreover, GAF, a specialty chemical company, also will remain as Carbide's largest single owner, with 10 percent of the firm's outstanding shares. GAF intends to "preserve its options" for the future, said Heyman. Heyman refused to speculate as to whether he would mount another raid on Carbide.

Carbide Chairman Warren Anderson said yesterday that "through the steadfast and resolute efforts of Carbide management," the company is "on track" with its internal reorganization. "We can now proceed without costly distractions," he said.

But the cost of Carbide's victory was so great that it left the company radically reshaped -- turning it into a debt-ridden firm in a severely weakened state, according to some financial analysts.

Since Heyman launched his initial bid on Dec. 9 with a junk-bond financed $4.1 billion offer for Carbide stock, Carbide has expedited a huge restructuring program it announced last August, offered to buy back 55 percent of its outstanding stock for an estimated $3.3 billion and initiated plans to sell off one of its "crown jewels" -- the $1.9 billion a year consumer products operation that makes such well-known household goods as Eveready batteries, Glad plastic bags and Prestone antifreeze.

According to documents filed last week with the Securities and Exchange Commission, the company's defensive maneuvers -- which some analysts have called a "scorched earth strategy" -- will cause Carbide's long-term debt to more than double, from $2.1 billion to $4.5 billion, and its short-term debt to balloon $908 million to $2 billion.

The value of its equity is expected to fall to $918 million from $4.3 billion, according to the documents.

Perhaps even more galling to Carbide managers, GAF will be the principal beneficiary of many of its antitakeover defenses.

In announcing its plan to sell off the consumer products division, Carbide said it would distribute the proceeds over book value directly to shareholders in the form of a special one-time dividend. Anderson has estimated that this will mean dividends of between $28 and $44 per share for Carbide stockholders. With GAF's 3.1 million shares, this would mean a cash windfall for the Wayne, N.J.-based firm of between $86 million and $136 million.

The takeover struggle has meant a bonanza for all Carbide shareholders as the company's stock price has risen from the low $30s immediately after the Bhopal poison gas leak last year to in excess of $70 a share. It closed yesterday at $71.50, down $1.75.

But it also has caused lawyers suing Carbide over the Bhopal tragedy to worry that the company has been left in such a weakened state that it will unable to meet claims to compensate the victims in India.

Many analysts were puzzled why Heyman would even be interested in Carbide with the Bhopal contingent liabilities.

But the GAF chairman said yesterday he always viewed Bhopal as a "manageable" problem.