Control over all internal and external degrees of freedom of molecules at the level of single quantum states will enable a series of fundamental studies in physics and chemistry(1,2). In particular, samples of ground-state molecules at ultralow temperatures and high number densities will facilitate new quantum-gas studies(3) and future applications in quantum information science(4). However, high phase-space densities for molecular samples are not readily attainable because efficient cooling techniques such as laser cooling are lacking. Here we produce an ultracold and dense sample of molecules in a single hyperfine level of the rovibronic ground state with each molecule individually trapped in the motional ground state of an optical lattice well. Starting from a zero-temperature atomic Mott-insulator state(5) with optimized double-site occupancy(6), weakly bound dimer molecules are efficiently associated on a Feshbach resonance(7) and subsequently transferred to the rovibronic ground state by a stimulated four-photon process with textgreater50% efficiency. The molecules are trapped in the lattice and have a lifetime of 8 s. Our results present a crucial step towards Bose-Einstein condensation of ground-state molecules and, when suitably generalized to polar heteronuclear molecules, the realization of dipolar quantum-gas phases in optical lattices(8-10).