Gray & Co. Public Communications International Inc., Washington's biggest lobbying and public relations firm, said yesterday it has agreed to be acquired by JWT Group Inc., a giant New York communications holding company.

In a transaction valued at about $21 million, Gray & Co. will become part of Hill and Knowlton Inc., the public relations subsidiary of JWT that was home for 20 years to Robert Keith Gray, who broke away in March 1981 to form his own company.

Gray will manage the Washington operations of Hill and Knowlton after they are merged with those of Gray & Co., and will become chairman a new division of Hill and Knowlton Public Affairs International. Gray also will be a member of Hill and Knowlton's board of directors and deputy chairman of its policy committee.

A former Eisenhower administration official and cochairman of President Reagan's inaugural committee, Gray built the company into a flamboyant and sometimes controversial international operation with annual revenue of more than $27 million, a bipartisan stable of high-powered political stars, and a client list that has included the Marxist government of Angola, the governments of Canada, Turkey and Morocco, and the Kennedy Center for the Performing Arts.

In early 1984, Gray sold one-quarter of the company in a public stock offering. Under the merger agreement, all Gray & Co. stockholders will receive JWT stock worth about $8.75 for each share of Gray & Co.

Gray, chairman and chief executive of the company, owns 67 percent of its stock, and thus will gain JWT stock worth about $14 million. Through the merger, Gray will own about 3.6 percent of JWT.

Other employes of Gray & Co. have exercised stock options worth less than 1 percent of the company's total outstanding shares and hold options worth about 10 percent of the outstanding shares, a Gray spokesman said.

The $8.75-a-share price was "a good deal" for JWT and "disappointing" for Gray & Co. stockholders, said financial analysts, who noted that Gray & Co. sold for $7.50 a share when it went public two years ago. The stock closed yesterday at $8.25, up 25 cents.

The merger price represents "a disappointing return relative to expectations," said George F. Shipp, an analyst with Investment Corp. of Virginia. "Clearly, the largest shareholder believed he struck the best deal. But it remains to be seen whether the best deal for him is necessarily the best deal for the outside shareholders."

Gray said the merger terms reflect "a very good price in today's market and an honest evaluation of the company," which has 184 employes and earned $1.2 million on revenue of $27.1 million in the fiscal year that ended Feb. 28.

Hill and Knowlton will honor all Gray & Co. contracts, but may not want to renew some of them, said Penney P. Burnett, JWT's vice president of investor relations. "There are certain types of business which Hill and Knowlton does not take," she said, declining to specify which types, but adding, "Those businesses know who they are."

Gray said he would be surprised if Hill and Knowlton tried to tone down his operations. "We've taken the toughest assignments, and I'm proud of that," he said. "We have color and flair and hopefully will inject that into Hill and Knowlton."

Analysts said the subject of Gray's "color and flair" probably was resolved during the merger negotiations. "For $14 million, Gray has probably agreed to be a little less flamboyant," Anschel said.

Gray had managed Hill and Knowlton's Washington operations, but left in 1981 after opposing the sale of Hill and Knowlton to JWT. He later sued JWT, but settled out of court in 1982.

Analysts said the merger will strengthen Hill and Knowlton's Washington presence and international operations. A global company with more than 1,300 employes, Hill and Knowlton reported revenue of $77 million in 1985. The parent company, JWT Group Inc., also owns J. Walter Thompson Co., the largest U.S. advertising agency.

Gray brings certain "personnel assets to the table," said Fred Anschel, an analyst with Dean Witter Reynolds Inc., referring to Gray himself and the politically "well-connected" heavyweights that have given Gray & Co. its luster.

Gray has complemented his own White House connections by hiring prominent Democrats such as Frank F. Mankiewicz, former president of National Public Radio and now a Gray & Co. executive vice president.

Gray & Co. also brings to the table a reputation for flamboyance and controversy that may not match Hill and Knowlton's lower-profile approach.

One Gray & Co. hire, Alejandro Orfila, former secretary general to the Organization of American States, was forced to resign after a questions were raised about payments made by Gray & Co.'s Madrid office to a Spanish politician.