Context. Neutrinos heavier than MZ/2 ∼ 45 GeV are not excluded by particle physics data. Stable neutrinos heavier than this might contribute to the cosmic gamma ray background through annihilation in distant galaxies, as well as to the dark matter content of the universe.Aims. We calculate the evolution of the heavy neutrino density in the universe as a function of its mass, MN, and then the subsequent gamma ray spectrum from annihilation of distant N ¯N (from 0 < z < 5).Methods. The evolution of the heavy neutrino density in the universe is calculated numerically. To obtain the enhancement due to structure formation in the universe, we approximate the distribution of N to be proportional to that of dark matter in the GalICS model. The calculated gamma ray spectrum is compared to the measured EGRET data.Results. A conservative exclusion region for the heavy neutrino mass is 100 to 200 GeV, both fromEGRET data and our re-evalutation of the Kamiokande data. The heavy neutrino contribution to dark matter is found to be at most 15%.