In search for effective negative electrodes for Mg- and K-ion batteries, we investigate the potential of glassy amorphous carbon by means of density functional theory calculations. Specifically, we provide the energetics for Mg and K insertion in two different structures of amorphous carbon. The insertion sites are found to be well distributed in energy, with insertion energies E
f
vs. the cohesive energies of respectively Mg and K ranging from -1.1 to 2.8 eV for Mg and from -1.0 to 3.7 eV for K. To compare amorphous carbon to the most common structure of carbon (graphite), we study in addition the energetics associated with the insertion of Mg and K in graphite, for which two different stackings are considered for the two layers intercalating the Mg/K atom: the AB stacking which is most stable at the initial state of charge (in pure graphite) and the AA stacking which is most stable at the known final state of charge of K (K
x
C, x = 1/8). Already at the low concentration considered (x = 1/128), the insertion of Mg and K in graphite is found to favor the AA stacking, and to be thermodynamically unfavored (E
f
positive with E
f
= 1.9 eV for Mg and E
f
= 0.7 eV for K). Amorphization appears therefore to provide insertion sites for Mg and K of lower (and negative) energies. The effect is of larger extent for Mg than for K, so much so that the insertion of Mg becomes more favored than that of K in amorphous carbon, although in graphite K is more easily inserted than Mg.