From the analysis of the flux of high energy particles, E > 3 · 10 18 eV, it is shown that the distribution of the power density of extragalactic rays over energy is of the power law, q ( E ) ∝ E −2.7 , with the same index of 2.7 that has the distribution of Galactic cosmic rays before the so called ‘knee', E 15 eV. However, the average power of extragalactic sources, which is of e ≃ 10 43 erg s −1 , exceeds by at least two orders the power emitted by the Galaxy in cosmic rays, assuming that the density of galaxies is estimated as N g ≃ 1 Mpc −3 . Considering that such power can be provided by relativistic jets from active galactic nuclei with the power e ≃ 10 45 − 10 46 erg s −1 , we estimate the density of extragalactic sources of cosmic rays as N g ≃ 10 −2 − 10 −3 Mpc −3 . Assuming the same nature of Galactic and extragalactic rays, we conclude that the Galactic rays were produced by a relativistic jet emitted from the Galactic center during the period of its activity in the past. The remnants of a bipolar jet are now observed in the form of bubbles of relativistic gas above and below the Galactic plane. The break, observed in the spectrum of Galactic rays (‘knee’), is explained by fast escape of energetic particles, E > 3 · 10 15 eV, from the Galaxy because of the dependence of the coefficient of diffusion of cosmic rays on energy, D ∝ E 0.7 . The obtained index of the density distribution of particles over energy, N ( E )∝ E −2.7−0.7/2 = E −3.05 , for E > 3 · 10 15 eV agrees well with the observed one, N ( E )∝ E −3.1 . The estimated time of the termination of the jet in the Galaxy is 4.2 · 10 4 years ago.