The Hubbard model underlies our understanding of strongly correlated materials. Whereas its standard form only comprises interactions between particles at the same lattice site, extending it to encompass long-range interactions is predicted to profoundly alter the quantum behavior of the system. We realize the extended Bose-Hubbard model for an ultracold gas of strongly magnetic erbium atoms in a three-dimensional optical lattice. Controlling the orientation of the atomic dipoles, we reveal the anisotropic character of the onsite interaction and hopping dynamics and their influence on the superfluid-to-Mott insulator quantum phase transition. Moreover, we observe nearest-neighbor interactions, a genuine consequence of the long-range nature of dipolar interactions. Our results lay the groundwork for future studies of exotic many-body quantum phases.