We describe methods for simulating general second-quantized Hamiltonians using the compact encoding, in which qubit states encode only the occupied modes in physical occupation number basis states. These methods apply to second-quantized Hamiltonians composed of a constant number of interactions, i.e., linear combinations of ladder operator monomials of fixed form. Compact encoding leads to qubit requirements that are optimal up to logarithmic factors. We show how to use sparse Hamiltonian simulation methods for second-quantized Hamiltonians in compact encoding, give explicit implementations for the required oracles, and analyze the methods. We also describe several example applications including the free boson and fermion theories, the φ4-theory, and the massive Yukawa model, all in both equal-time and light-front quantization. Our methods provide a general-purpose tool for simulating second-quantized Hamiltonians, with optimal or near-optimal scaling with error and model parameters.