Pan Am Corp. completed a deal to sell important trans-Atlantic routes to UAL Corp. in a $400 million package that apparently scuttled a takeover proposal by Trans World Airlines Inc.

The deal signed late Wednesday marks a major expansion for United Airlines and will give it a strong presence flying across the Pacific and Atlantic. UAL Corp. is United's parent.The agreement, originally announced last month, was put in question over the weekend after TWA proposed merging with Pan Am. If the papers hadn't been signed by Wednesday, the United deal could have been called off and TWA's offer might have come into play.

TWA Chairman Carl Icahn had offered Pan Am securities with a face value of $300 million and $150 million in cash if it didn't sell the routes to UAL Corp.

Meanwhile, Eastern Airlines has persuaded a federal bankruptcy judge to let it draw $15 million from an escrow account to keep on flying, thwarting efforts by creditors - at least for now - to close the airline.

Judge Burton R. Lifland ruled late Wednesday that Eastern can take the money from the $273.6 million account now and draw another $15 million next month if it can prove it is making strides toward financial recovery.

"There's a great sense of relief," Eastern spokesman Jim Ashlock said afterward. "This was the big one."

Eastern's creditors, who include banks, airplane companies and unions, had demanded the airline be closed and its assets sold off because it has no realistic chance at becoming healthy.

Under the Pan Am-United deal, UAL will acquire Pan Am's U.S.-to-London routes, except for those from Miami and Detroit.

UAL will also buy gates and hangar and office space at San Francisco and Washington's Dulles International airport, two Boeing 747 jumbo jets and spare parts.

Pan Am said the deal also involved a marketing agreement under which the rival airlines will coordinate some flights and attempt to feed passengers to one another.