The present invention provides a method for the N-demethylation and/or N-acylation of an N-methylated heterocycle such as morphine alkaloids or tropane alkaloids. The method comprises reacting the heterocycle with an acylating agent in the presence of a metal catalyst.