We present a framework for the end-to-end optimization of metasurface imaging systems that reconstruct targets using compressed sensing, a technique for solving underdetermined imaging problems when the target object exhibits sparsity (e.g., the object can be described by a small number of nonzero values, but the positions of these values are unknown). We nest an iterative, unapproximated compressed sensing reconstruction algorithm into our end-to-end optimization pipeline, resulting in an interpretable, data-efficient method for maximally leveraging metaoptics to exploit object sparsity. We apply our framework to super-resolution imaging and high-resolution depth imaging with a phase-change material. In both situations, our end-to-end framework effectively optimizes metasurface structures for compressed sensing recovery, automatically balancing a number of complicated design considerations to select an imaging measurement matrix from a complex, physically constrained manifold with millions of dimensions. The optimized metasurface imaging systems are robust to noise, significantly improving over random scattering surfaces and approaching the ideal compressed sensing performance of a Gaussian matrix, showing how a physical metasurface system can demonstrably approach the mathematical limits of compressed sensing.