Insights into complex phenomena in quantum matter can be gained from simulation experiments with ultracold atoms, especially in cases where theoretical characterization is challenging. However, these experiments are mostly limited to short-range collisional interactions; recently observed perturbative effects of long-range interactions were too weak to reach new quantum phases. Here we experimentally realize a bosonic lattice model with competing short- and long-range interactions, and observe the appearance of four distinct quantum phases--a superfluid, a supersolid, a Mott insulator and a charge density wave. Our system is based on an atomic quantum gas trapped in an optical lattice inside a high-finesse optical cavity. The strength of the short-range on-site interactions is controlled by means of the optical lattice depth. The long (infinite)-range interaction potential is mediated by a vacuum mode of the cavity and is independently controlled by tuning the cavity resonance. When probing the phase transition between the Mott insulator and the charge density wave in real time, we observed a behaviour characteristic of a first-order phase transition. Our measurements have accessed a regime for quantum simulation of many-body systems where the physics is determined by the intricate competition between two different types of interactions and the zero point motion of the particles.