American Hospital Supply Corp., the world's largest supplier of hospital products, has agreed to a merger with Baxter Travenol Laboratories Inc., the world's largest purveyor of intravenous solutions, in a friendly $3.8 billion merger that ends a bitter takeover fight for American.

The announcement ends the battle between Baxter and Hospital Corp. of America, the nation's largest for-profit hospital company, for control of American. HCA and American previously had agreed to merge at a price much lower than Baxter's offer, but HCA agreed to walk away from that deal and to support the Baxter-American merger in return for up to $200 million in payments.

"I am extremely pleased that our two companies have reached agreement on this landmark combination," said Baxter President Vernon R. Loucks. "Our goal is to build on the strengths of both organizations to create a strong and independent source of supply for all hospitals and health care providers, able to make an important contribution toward containing health care costs all along the delivery chain, internationally as well as in the U.S."

American Chairman Karl D. Bays, who until yesterday had been critical of Baxter's unsolicited takeover bid, said yesterday that Baxter's offer was simply too good to refuse. Bays previously had said he preferred a merger with HCA, even though it was offering about $15 a share less for American, because he said that combination was in American's best long-run interest.

"After lengthy deliberation and careful consideration of our alternatives, American's board concluded that a merger with Baxter Travenol on these substantially improved terms would serve the best interests of our shareholders," Bays said yesterday.

Under terms of the proposed merger, which was approved unanimously by directors of both companies yesterday, Baxter will pay $51 a share in cash for up to 53 percent of American's shares, and $51 a share in securities for the rest. The securities portion will consist of $25 in market value of Baxter common stock, $16 in market value of Baxter convertible exchangeable preferred stock and $10 in market value of Baxter adjustable rate preferred stock.

"By rejecting earlier unfriendly Baxter offers, the American board was able to get about another $11 a share for its stockholders," said Geoffrey T. Boisi, head of the Goldman Sachs merger department, who represented American in the negotiations. "When we sat down with the American board on Friday, they had a variety of options before them. They decided if we could achieve full value for their shareholders from Baxter, then that might be the appropriate way to go."

American, Baxter and HCA have agreed that HCA will receive $150 million on the effective date of the American-Baxter merger in return for supporting the deal. In addition, HCA will receive $50 million in 1991 if its aggregate purchases under a five-year supply agreement with American exceed $1.325 billion. HCA also agreed not to cancel supply agreements with Baxter and American, which it had threatened to do last week if Baxter did not drop its takeover bid.

The merger is subject to approval of the shareholders of both companies as well as clearance from either the Justice Department or the Federal Trade Commission. Baxter said earlier that it was likely that certain overlapping businesses would have to be sold prior to completion of a merger with American.

"What we can do through this merger is build a substantially better scale for coping with an environment, which is overwhelmingly driven by the economics of the picture," said Baxter's Loucks, who will be chief executive officer of the new company. "I think scale in this marketplace is important because the industry is going through a shakeout. Hospital occupancy rates are down considerably and ultimately that will result in the closing of some hospitals. This gives us a broader base to operate across with some synergy between the companies.

Baxter, which closed yesterday at 14, off 1 3/4, had revenue of $1.8 billion and net income of $29.1 million last year. American, which closed up 3 7/8 at 46, had revenue of $3.5 billion and net income of $237.8 million last year.