John D. Wirth, a scholar and historian of Latin American affairs with an interest in Canada, died in Toronto. He was 66 and lived in Atherton, Calif., and Santa Fe, N.M. The cause was a heart aneurysm he suffered while addressing the Friends of Fort York, a Canadian history organization, the North American Institute announced. In 1988, Mr. Wirth founded the institute, one of the first academic institutes focused on the three nations of mainland North America. . Afterward, he traveled regularly to Canada and Mexico while teaching Canadian and Latin American history at Stanford University, where he was the Gildred professor of Latin American studies. He formally retired in June 2002. Mr. Wirth wrote or edited several books, including ''Identities in North America: The Search for Community'' and ''Smelter Smoke in North America: The Politics of Transborder Pollution.'' Mr. Wirth was born in Dawson, N.M., the son of Virginia and Cecil Wirth, headmaster of the Los Alamos Ranch School. He attended high school in Denver and at the Putney School in Putney, Vt. He graduated magna cum laude from Harvard University in 1958 and received a doctorate in Latin American history from Stanford in 1967. Mr. Wirth is survived by his wife, Nancy Meem Wirth; three sons, Peter, Timothy and Nicholas; two brothers, John Wiebenson and Timothy E. Wirth, a former United States senator; and two sisters, Carla Henebry and Mary Gilland.