American Airlines said last night it plans to buy all of Trans World Airline's service from the United States to London, just two months after American's chief rival, United Airlines, announced a similar deal with Pan American World Airways.

The American deal heightens and carries abroad the rivalry between American and United, the nation's two largest airlines. It also underscores the decline of TWA and Pan Am, airlines that pioneered the transatlantic market but are now badly weakened.

The deal also may pave the way for Trans World Airlines Inc. Chairman Carl Icahn to attempt a takeover of rival Pan Am Corp., according to one source.

Under the deal announced last night, American Airlines Inc. will pay TWA $445 million for its rights to fly to London, the major gateway to Europe for U.S. travelers, and for related facilities.

American said it will sell stock in the first quarter of 1991 to help fund the deal.

A separate agreement would also transfer TWA's takeoff and landing rights at Chicago's O'Hare International Airport and facilities there to American for $70 million. Both United and American operate major hubs of operations at Chicago, but United's hub has been substantially bigger. The deal with TWA would give American "near parity with our primary competitor there," said American Chairman Robert L. Crandall.

When United and Pan Am announced in October that Pan Am would sell its valuable routes to Heathrow Airport as part of a $400 million deal, Crandall immediately offered to top United's bid. That met a cold shoulder from Pan Am.

American now has essentially replicated the deal with another carrier. As in the United-Pan Am deal, American and TWA also will link their frequent flier programs and cooperate in other marketing ventures.

"This puts real pressure on British Airways," said Shearson-Lehman Brothers Inc.'s Robert J. Joedicke.

British Airways has benefited from competing against two weak carriers, TWA and Pan Am, the only carrier's with permission from the British government to fly to Heathrow. Other U.S. carriers have had to use the less desirable Gatwick and Manchester airports.

One question surrounding the United-Pan Am deal was how Great Britain could be persuaded to allow United to succeed Pan Am in that authority, assuming U.S. regulators approved the purchase. American's deal with TWA now will increase the pressure on British authorities to do so, analysts said.