Abstract: Understanding the physics of galaxy formation is arguably among the greatest problems in modern astrophysics. Recent cosmological simulations have demonstrated that "feedback" by star formation, supernovae and active galactic nuclei appears to be critical in obtaining realistic disk galaxies, to slow down star formation to the small observed rates, to move gas and metals out of galaxies into the intergalactic medium, and to balance radiative cooling of the low-entropy gas at the centers of galaxy clusters. However the particular physical processes underlying this "feedback" still remain elusive. In particular, these simulations neglected cosmic rays and magnetic fields, which provide a comparable pressure support in comparison to turbulence in our Galaxy, and are known to couple dynamically and thermally to the gas. Using hydrodynamic simulations of galaxy formation, I will show how cosmic rays are able to drive powerful galactic winds in low-mass galaxies. This reduces the available amount of gas for star formation and implies a shallower slope of the faint-end of the galaxy luminosity function as required by observations. In the second part of the talk I demonstrate that cosmic-ray heating can balance radiative cooling of the low-entropy gas at the centers of galaxy clusters and helps in mitigating the star formation of the brightest cluster galaxies. New data on the low-frequency radio and gamma-ray emission of M87, the closest active galaxy interacting with the cooling cluster plasma, enable us to put forward a comprehensive, physics-based model of feedback by active galactic nuclei.