Aims. We study the evolution of the luminosity function (LF) of type-1 and type-2 Active Galactic Nuclei (AGN) in the mid-infrared, and then derive the contribution of the AGN to the Cosmic InfraRed Background (CIRB) and the expected source counts to be observed by Spitzer at 24 µm. Methods. We used a sample of type-1 and type-2 AGN selected at 15 µm (ISO) and 12 µm (IRAS), and classified on the basis of their optical spectra. Local spectral templates of type-1 and type-2 AGN have been used to derive the intrinsic 15 µm luminosities. We adopted an evolving smooth two-power law shape of the LF, whose parameters have been derived using an un-binned maximum likelihood method. Results. We find that the LF of type-1 AGN is compatible with a pure luminosity evolution. A small flattening of the faint (L 15 < L * 15 ) slope of the LF with increasing redshift is favoured by the data. A similar evolutionary scenario is found for the type-2 population with a rate k L ranging from ∼1.8 to 2.6, depending significantly on the adopted mid-infrared spectral energy distribution. Also for type-2 AGN a flattening of the LF with increasing redshift is suggested by the data, possibly caused by the loss of a fraction of type-2 AGN hidden within the optically classified starburst and normal galaxies. The type-1 AGN contribution to the CIRB at 15 µm is (4.2-12.1)× 10 −11 Wm −2 sr −1 , while the type-2 AGN contribution is (5.5-11.0)× 10 −11 W m −2 sr −1 . We expect that Spitzer will observe, down to a flux limit of S 24 µm =0.01 mJy, a density of ∼1200 deg −2 type-1 and ∼1000 deg −2 type-2 optically classified AGN. Conclusions. AGN evolve in the mid-infrared with a rate similar to the ones found in the optical and X-rays bands. The derived total contribution of the AGN to the CIRB (4-10%) and Spitzer counts should be considered as lower limits, because of a possible loss of type-2 sources caused by the optical classification.