The cosmic formation rate of long gamma-ray bursts (LGRBs) encodes the evolution, across cosmic times, of the properties of their progenitors and of their environment. The LGRB formation rate and the luminosity function, with its redshift evolution, are derived by reproducing the largest sets of observations collected over the last four decades, namely the observer-frame prompt emission properties of the GRB samples detected by the Fermi and Compton Gamma Ray Observatory satellites and the redshift, luminosity, and energy distributions of the flux-limited, redshift-complete samples of GRBs detected by Swift. The model that best reproduces all these constraints consists of a GRB formation rate increasing with redshift ∝(1 + z)3.2, i.e., steeper than the star formation rate, up to z ∼ 3, followed by a decrease ∝(1 + z)−3. On top of this, our model also predicts a moderate evolution of the characteristic luminosity function break ∝(1 + z)0.6. Models with only luminosity or rate evolution are excluded at >5σ significance. The cosmic rate evolution of LGRBs is interpreted as their preference for occurring in environments with metallicity
12
+
log
(
O
/
H
)
<
8.6
, consistent with theoretical models and host galaxy observations. The LGRB rate at z = 0, accounting for their collimation, is
ρ
0
=
79
−
33
+
57
Gpc−3 yr−1 (68% confidence interval). This corresponds to ∼1% of broad-line Type Ibc supernovae producing a successful jet in the local universe. This fraction increases up to ∼7% at z ≥ 3. Finally, we estimate that at least ≈0.2−0.7 yr−1 of the Swift- and Fermi-detected bursts at z < 0.5 are jets observed slightly off-axis.