We study the evolution of the luminosity function (LF) of type-1 and type-2 AGN in the mid-infrared, and derive their contribution to the Cosmic InfraRed Background (CIRB) and the expected deep source counts to be observed by Spitzer at 24 micron. The sample of type-1 and type-2 AGN was selected at 15 micron (ISO) and 12 micron (IRAS), and classified on the basis of their optical spectra. Local templates of type-1 and type-2 AGN have been used to derive the intrinsic 15 micron 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. We find that the LF of type-1 AGN is compatible with a pure luminosity evolution (L(z)=L(0)(1+z)^k_L) model where k_L~2.9. A small flattening of the faint 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 micron is (4.2-12.1) x 10e-11 W m^-2 sr^-1, while the type-2 AGN contribution is (5.5-11.0) x 10e-11 W m^-2 sr^-1. We expect that Spitzer will observe, down to a flux limit of S_24 = 0.01 mJy, a density of ~1200 deg^-2 type-1 and ~1000 deg^-2 type-2 optically classified AGN. The derived total contribution of the AGN galaxies 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.