John Moors Cabot, 79, a career diplomat who served as U.S. consul general in Shanghai when the communists came to power in China, as U.S. minister to Finland and as U.S. ambassador to four other countries, died Monday at Georgetown University Hospital. He had a stroke last week. d

Mr. Cabot joined the Foreign Service in 1926. His last post as ambassador was in Poland, where he served from 1962 to 1965. During those years, he was responsible, among other things, for representing the United States in its only regular contacts with the Peoples Republic of China. These took place in Warsaw for several years. From 1965 to 1966, he was deputy commandant of the National War College. He had been in retirement since then. His permanent rank in the Foreign Service was minister.

Much of Mr. Cabot's career was spent in Latin America. He was an early and outspoken advocate for U.S. economic aid that part of the world and for social reform in Latin American politicial systems.

The second major portion of his career was in communist countries. In 1947, he was appointed counsellor of the U.S. Embassy in Belgrade, Yugoslavia. He was credited during this period with foreseeing the possibility of a break between Marshal Tito, the Yugoslav leader, and Marshal Stalin of the Soviet Union. This split -- the first major rupture in the monolithic front of world communism -- occurred a year later.

From 1948 to 1949, Mr. Cabot was consul-general in Shanghai. When the communists took the city, normal relations between U.S. and Chinese diplomats virtually ceased. At one point, Chinese who had been employed by the U.S. Navy took over the consulate and demanded wages they claimed were owed to them.

It was largely because of his experience in China that Mr. Cabot was appointed ambassador to Poland by President Kennedy in 1961. Apart from his contacts with the Chinese there, he was a forthright critic of a congressional effort to end "most-favored-nation" treatment to all communist regimes. In effect, this meant cutting off good trade terms for Poland and Yugoslavia, the only two communist nations that received this assistance. George Kennan, the U.S. ambassador to Yugoslavia at the time, joined Mr. Cabot in his protest and the aid was continued.

Mr. Cabot was born in Cambridge, Mass. His parents were Godfrey Lowell and Maria Moors Cabot. (The Maria Moors Cabot prize for reporting from Latin America was established by his father and named after his mother). He was educated at Harvard and Oxford universities.

His first Foreign Service assignment was as a consul in Callao-Lima, Peru, in 1927. For the next eight years, he served in the Dominican Republic, Mexico and Brazil. From 1935 to 1939, he served first in the Netherlands and then in Sweden. From 1939 to 1941, he was in Guatemala.

During much of World War II, Mr. Cabot was in the State Department as assistant chief of the division of Aemerican Republics and then as chief of the division of Caribbean and Central American affairs. His assignment to Belgrade followed another tour of duty in Argentina.

In 1953, President Dwight D. Eisenhower appointed Mr. Cabot assistant secretary of state for Inter-American affairs. It was in this position that he was able to give wide currency to his views on economic aid and social reform in Latin America. He was dropped from the post because of a dispute with George Humphrey, Eisenhower's acerbic and economy-minded secretary of the Treasury.

Mr. Cabot was named U.S. minister to Finland in 1950. At that time, he was the highest ranking American diplomat in that country. He was ambassador to Sweden from 1954 to 1957, ambassador to Colombia from 1957 to 1959 and ambassador to Brazil from 1959 to 1961.

Mr. Cabot's survivors include his wife, the former Elizabeth Lewis, whom he married on April 2, 1932, of their residences in Washington and Manchester, Mass.; four children, Mrs. Antonio Enriquez of Mexico City, John G. L., of Pride's Crossing, Mass., Lewis P., of Boston, and Mrs. Bogislav von Wentzel of Hamburg, Germany; one brother, Thomas D., of Weston, Mass.; a sister, Mrs. Ralph Bradley of Manchester, and 11 grandchildren.

The family suggests that expressions of sympathy be in the form of contributions to the American Foreign Service Scholarship Fund, 2101 E St. NW, Washington, D.C., 20037.