Like a "white knight" riding to the rescue, Geico Corp. yesterday agreed to protect the independence of neighboring Avemco Corp. by buying out two big speculators who own 17 percent of Avemco's stock.

The $6.1 million purchases will make the Geico health, life and accident insurance companies the largest stockholder in Avemco, which insures and finances small airplanes.

Geico Chairman John J. Byrne said Geico will name one person to Avemco's board of directors but has no plans to try to take control of the other insurance company.

Top executives of Geico and Avemco have had close ties for many years. Geico bought about 5 percent of Avemco's stock last December, shortly after two conglomerates began investing in Avemco and it appeared likely one or the other would try to take over the company.

Geico officals said the decide to purchase additional Avemco shares was made "as an investment."

When Geico first bought into Avemco last year, the move was viewed as an effort by Geico to play the role of "white knight" for an old neighbor. In the language of Wall Street take-over specialists, a "white knight" is a company that rides to the rescue to protect a friendly firm from an unwanted takeover.

Under the agreement announced yesterday by Byrne and Avemco Chairman Arnold H. Johnson, Geico will buy all the Avemco shares owned by Unicorp Financial Corp., a Canadian investment company, and Associated Madison Companies -- a firm controlled by Gerald Tsai Jr., a well-known Wall Street financier.

Geico agreed to pay $14.05 a share for the Avemco stock owned by Unicorp and Associated Madison, which bought their stock last summer when it was selling for from $5 to $9 a share. In trading on the American Stock Exchange yesterday, Avemco closed up 1/2 at 12 3/8.

The 435,000 shares of Avemco stock will cost Geico about $6.1 million.

Johnson said the agreement with Geico, "puts 22.5 percent of the stock in the hands of someone we know under terms we feel comfortable with" and ends months of uncertainty about the future of the small but highly profitable company.

Geico agreed not only to buy the Avemco shares from the other two firms but also to vote along with Avemco's management in corporate elections and to support any merger or acquistiion recommended by Avemco's board. Geico promised that for three years it would not sell the stock except with the consent of the Avemco board or in a manner "designed to distribute its holding widely."

The agreement between top executives of the two companies requires the approval of Avemco's board of directors and also of the Maryland insurance commissioner.