The invention discloses a transmethylase gene in a betaine synthesis process, and modification and application thereof. The method comprises the following steps: cloning glycine sarcosine N-transmethylase gene (ApGSMT2) and dimethyl glycine N-transmethylase gene (ApDMT2) from aphanothece halophytica, substituting codons with lower occurrence possibility in higher plants in the ApGSMT2 and the ApDMT2 with higher plant preferred codons to generate a gene ApGSMT2d and a gene ApDMT2d, and constructing the serial genes, of which the coded products are respectively positioned in the chloroplast, byprotein locating targeting sequence and transmethylase gene fusion. Glycine and sarcosine are used as the substrates, the methylation of the glycine is catalyzed, the methylation of the dimethyl glycine is catalyzed by ApDMT, and the glycinebetaine is synthesized under the concerted catalysis. The ApGSMT2/ApDMT2 or modifier genes thereof are synergically transferred into corn, wheat, cotton, soybean, tobacco and other crops, so high-concentration glycinebetaine is accumulated in the cells, thereby obviously enhancing the stress tolerance of the plant.