The present invention relates to novel heterocyclic compounds of formula (I), wherein the variables are as defined in the claims or the description, which are useful for inhibiting glycogen synthase kinase 3 (GSK-3), compositions containing the compounds, their use for preparing a medicament for the treatment of a medical disorder susceptible to the treatment with a compound that modulates, preferably inhibits, the activity of glycogen synthase kinase 3β, and methods of treatment of medical disorders susceptible to treatment with a compound that modulates glycogen synthase kinase 3β activity using the compounds.