The reaction of (1-ethoxyethylidene)malononitrile with cyanoacetamide or cyanothioacetamide yielded 6-amino4-methyl-2-(thio)oxo-1,2-dihydropyridine-3,5-dicarbonitriles. The resulting pyridine derivatives enter into an aminomethylation reaction with an excess of formaldehyde and primary amines with the formation of previously unknown 8-methyl-6-oxo-3-R-1,3,4,6-tetrahydro-2 H -pyrido[1,2- a ][ 1,3,5]triazine-7,9-dicarbonitriles. Further treatment of 6-amino-4-methyl-2-thioxo-1,2-dihydropyridine-3,5-dicarbonitrile and its oxygen analogue with excess formaldehyde leads to the formation of 3,10-dimethyl-1,8-dithioxo-5,6,12,13-tetrahydro-1 H ,8 H -dipyrido[1,2- a :1’,2’- e ][1,3,5,7]tetrazocin-2,4,9,11-tetracarbonitrile and 6,6’-[methylenedi(imino)]bis(4-methyl-2-oxo-1,2-dihydropyridine-3,5-dicarbonitrile), respectively. These compounds show a pronounced antidote effect against the herbicide 2,4-D (2,4-dichlorophenoxyacetic acid) in laboratory and field experiments on sunflower seedlings. Also, 6-amino-4-methyl-2-oxo-1,2-dihydropyridine-3,5-dicarbonitrile exhibits pronounced anticorrosion properties and is an adsorption-type corrosion inhibitor. The mechanism of anti-corrosion action was studied in detail using X-ray photoelectron spectroscopy.