Retired Navy Capt. William F. Cafferata, 58, whose last assignment had been in the office for NATO planning of the Defense Department, died Wednesday at Fairfax Hospital after a heart attack.

Since his retirement in 1971, he had lived in Eagles Mere, Pa., where he was a real estate broker and land developer. He was visiting relatives here when he was stricken.

While on duty at the Defense Department from 1966 until retiring, Capt. Cafferata lived in Fall Church. Earlier he had been in the Office of the Joint Chiefs of Staff here from 1955 to 1957.

He was commanding officer of the destroyer USS Blandy, which carried the bodies of the unknown soldiers of World War II and the Korean conflict up the Potomac River for burial in Arlington Cemetery in 1958.

Capt. Cafferata was born in Chicago. He graduated from the Naval Academy at Annapolis in 1943, and served in the Pacific in World War II. His decorations included the Bronze Star.

His other assignments included command of a destroyer squadron in the 1961 Cuban crisis of the Bay of Pigs, and serving as joint chieft of the naval section of the Military Assistance Advisory Group in Belgium during 1963-66.

He is survived by his wife, Juliet Ruth, of the home; three children, Christopher, of Falls Church, Jody, of Washington, and Lee Ann, of Tehran, Iran, and two sisters, Mrs. Leonard Maloney, of Des Plaines, Ill., and Mrs Fred Garlock of Framingham, Mass.

The family suggests that expressions of sympathy may be in the form of contributions to the U.S. Naval Academy Alumni Association, Class of 1943 fund, in Annapolis.