Space-charge effects set stringent limits on the performance frontier high power proton accelerators. They manifest themselves in the beam losses and emittance growth. In principle, compensation of the space-charge effects in positively charged proton beams should be possible by negatively charged electron lenses which employ high brightness magnetized and externally controlled electron beams. While the method was previously assessed theoretically and in simplified tracking simulations, it has never been modeled by PIC codes to get reliable quantitative estimates of the efficiency of the compensation. Here we report on the first evidence using the Synergia particle-in-cell simulation code that a suitable number of electron lens type elements can protect the machine from emittance growth caused by space-charge forces in a model beam optics lattice with imperfections. For the effective electron lens space-charge compensation, the compensating elements must be placed within the betatron phase advance from each other. Electron lens elements could become the basis of new generation of high power proton and ion rapid cycling synchrotrons.