The Hillman Co., a privately owned Pittsburgh business with holdings in banking, heavy equipment and mining, yesterday agreed to buy M.S. Ginn & Co., Washington's biggest office supply firm.

Hillman offerred approximately $9 million in cash for Ginn, which last year had sales of $38.7 million, the two companies announced.

The sale must be approved by Ginn's shareholders, but that is considered a formality because Ginn's chairman, Marsh S. Marshall, owns more than 50 percent of the stock.

Under terms of the offer, Marshall will get not only about $4.5 million in cash but also a consulting contract with the new owners.

Terms of the agreement were not announced, but the company said it "would also require an agreement by Mr. Marshall not to compete with and to provide consulting services to the purchaser after termination of his employment for separate consideration."

Neither Marshall nor executives of Hillman could be reached for comment yesterday.

A long-established Pittsburgh investment company founded by the Hillman family, the Ginn buyer is a privately held business that makes few details of its operations public. Hillman investments include Pittsburgh National Bank, the Hillman Coal Co., heavy equipment manufacturing firms and chemical plants.

Hillman "has no prior operations" in Ginn's field and plans to "continue Ginn's operations as at present, with the same management," the announcement said.

A Hillman affiliate, which was not name, will purchase the assets of Ginn and assume its liabilities, the announcment said.

The purchase price is equivalent to $12.25 a share for Ginn stock, which has traded recently for about $8.75. Trading in Ginn's stock was suspended Friday by the National Association of Securities Dealers after potential takeover was announced.

Ginn said its board of directors is "still considering what course of action might be taken with the cash proceeds of the proposed sale."

George Ferris Jr., a Washington stockbroker and a member of Ginn's board, said the company is considering a merger method that would minimize the capital gains tax implcations of a cash sale. Usually a cash buyout requires stockholders to pay capital gains taxes on the sale price of the stock, which in this case is about 3.5 times the price at which the stock was sold to the public, accounting for stock splits.

The agreement in principal to purchase the firm is based on the condition that Ginn show a minimum net worth of $6.9 million. As of last June the company's net worth was just over $6 million.

Incorporated in the District of Columbia in 1928, Ginn first sold stock to the public in 1970.

Marshall became executive vice president and a director of the company in 1951, took over as president in 1965, and was the sole stockholder until the public offering.

Ginn has 11 stores. The latest, at Courthouse Square in Fairfax, opened yesterday, replacing an older location a few blocks away.

Selling office supplies furniture and equipment, the firm does about half its business with the federal government. Recently it has expanded into mail order office supply sales and business interior design.