Trans World Airlines Inc., maneuvering to avoid a takeover by corporate raider Carl Icahn, yesterday agreed to be acquired by Texas Air Corp. for $793.5 million in a merger that would create the nation's second-largest airline.

The proposed acquisition is another coup for Texas Air Chairman Frank Lorenzo, who has taken advantage of deregulation to build an airline empire that already includes Continental Airlines and New York Air. Lorenzo said yesterday that TWA would be operated as an independent subsidiary of Houston-based Texas Air, and would retain its present management and name. Related story on Page F1.

The combination of TWA, Continental Airlines and New York Air would rank by most measures as the nation's second-largest airline, well behind United Air Lines but slightly larger than American Airlines. Together, the three Texas Air companies would have about 300 aircraft and 40,000 employes. Texas Air's combined revenue would be $5 billion annually, making it the nation's third-largest airline holding company behind UAL Inc. (United Air Lines) and AMR Corp. (American Airlines). The holding-company operations include properties outside the airline industry.

By adding TWA, Texas Air would fill many of the gaps between New York Air's primarily East Coast operations and Continental's coverage of the western part of the country, because TWA's primary domestic hub is in St. Louis. "That builds, when you put it together, into a fairly strong network," said George James, an analyst at Washington-based Airline Economics Inc.

In addition, the combination of the three airlines' schedules would bolster TWA's already strong international service by providing feeder flights from around the nation into the airline's New York hub for international flights. TWA is the industry leader on the lucrative North Atlantic air routes.

Icahn, who owns nearly one-third of TWA's stock, had no immediate comment on the proposed takeover. Icahn had been offering a total of $600 million for TWA in a hostile takeover bid. Icahn is not expected to try to top the Texas Air offer. As a result of that offer, however, Icahn stands to make nearly $100 million on his TWA stock holdings.

Under the merger agreement, which is subject to approval by TWA stockholders and government regulators, the stockholders will receive $23 for their stock from Texas Air -- $19 in cash and $4 in a new issue of preferred stock. TWA stock closed on the New York Stock Exchange yesterday at $20.25, up 62.5 cents in active trading; Texas Air was down 50 cents to $13.37.

TWA's board agreed to the Texas Air offer just a day after a state judge in Missouri lifted a restraining order that had barred Icahn from pursuing his $18-a-share takeover bid. The Missouri court action followed another critical defeat for TWA in its effort to block Icahn's bid. The Department of Transportation Tuesday refused a TWA request to consider lifting the airline's fitness certificate in the event of a takeover by Icahn. TWA had argued that Icahn was unfit to run an airline because of his lack of experience in the industry and his wheeler-dealer style.

Icahn began stalking TWA several weeks ago, and the airline has been searching for a merger partner ever since. TWA had been reported to be in talks with Resorts International Inc., the hotel and casino operator, before settling on Texas Air's offer.

Texas Air began life as Texas International Airlines, a scrappy regional carrier that took advantage of airline deregulation in the late 1970s to grow dramatically beyond its original base in Texas. In 1980, the company formed New York Air to provide service, generally at discount prices, in the eastern half of the United States.

Under Lorenzo's leadership, Texas Air made an unsuccessful bid to take over National Airlines -- later bought by Pan Am -- and then used profits from that attempt to help fund a $200 million buyout of Continental Airlines in 1981, giving the airline, which took Continental's name but kept its corporate identity, coast-to-coast service.

Texas Air's operations generally have been characterized by tight management and low labor costs. New York Air was set up as a nonunion carrier, and Continental stirred a great deal of controversy two years ago by filing for bankruptcy protection to enable it to break high-cost union contracts. TWA's labor costs, by contrast, are among the highest in the industry.

Yesterday, the Independent Federation of Flight Attendants, which has been negotiating a contract with TWA for more than a year, said it would not stand for Texas Air-type tough labor policies should the takeover be completed.