We present the first chiral effective theory derivation of the neutrinoless double beta-decay nn → pp potential induced by light Majorana neutrino exchange. The effective-field-theory framework has allowed us to identify and parameterize short-and long-range contributions previously missed in the literature. These contributions can not be absorbed into parameterizations of the single nucleon form factors. Starting from the quark and gluon level, we perform the matching onto chiral effective field theory and subsequently onto the nuclear potential. To derive the nuclear potential mediating neutrinoless double beta-decay, the hard, soft and potential neutrino modes must be integrated out. This is performed through next-to-next-to-leading order in the chiral power counting, in both the Weinberg and pionless schemes. At next-to-next-to-leading order, the amplitude receives additional contributions from the exchange of ultrasoft neutrinos, which can be expressed in terms of nuclear matrix elements of the weak current and excitation energies of the intermediate nucleus. These quantities also control the two-neutrino double beta-decay amplitude. Finally, we outline strategies to determine the low-energy constants that appear in the potentials, by relating them to electromagnetic couplings and/or by matching to lattice QCD calculations.