The nonlinear optical properties of a plasma due to the relativistic electron motion in an intense laser field are of fundamental importance for current research and the generation of brilliant laser-driven sources of particles and photons1-15. Yet, one of the most interesting regimes, where the frequency of the laser becomes resonant with the plasma, has remained experimentally hard to access. We overcome this limitation by utilizing ultrathin carbon nanotube foam16 (CNF) targets allowing the strong relativistic nonlinearities at near- critical density (NCD) to be exploited for the first time. We report on the experimental realization of relativistic plasma optics to spatio-temporally compress the laser pulse within a few micrometers of propagation, while maintaining about half its energy. We also apply the enhanced laser pulses to substantially improve the properties of an ion bunch accelerated from a secondary target. Our results provide first insights into the rich physics of NCD plasmas and the opportunities waiting to be harvested for applications.