Abstract: We computed the contribution from clusters of galaxies to the diffuse gamma-ray and neutrino background. Clusters of galaxies can potentially produce cosmic rays (CRs) up to very-high energies via large-scale shocks and turbulent acceleration. Due to their unique magnetic-field configuration, CRs with energy ≤ 10^17 eV can be trapped within these structures over cosmological time scales, and generate secondary particles, including neutrinos and gamma rays, through interactions with the background gas and photons. We employ three-dimensional cosmological magnetohydrodynamical (MHD) simulations of structure formation to model the turbulent intergalactic medium. We use the distribution of clusters within this cosmological volume to extract the properties of this population. We propagate CRs in this environment using multi-dimensional Monte Carlo simulations across different redshifts (from z~5 to z=0), considering all relevant photohadronic, photonuclear, and hadronuclear interactions. We also include the cosmological evolution of the CR sources. We have computed the flux of high-energy gamma-rays (E > 10^9 eV) and found that the clusters contribute to a sizable fraction to the gamma-ray flux observed by Fermi-LAT.