A straightforward and general method has been developed for the synthesis of benzo[4,5]imidazo[1,2-a]pyrimidine and [1,2,4]triazolo[1,5-a]pyrimidine derivatives by simply combining 2-aminobenzimidazole or 3-amino-1,2,4-triazole, aldehyde, and β-dicarbonyl compound in the presence of a catalytic amount of thiamine hydrochloride (VB1). The advantages of this method are the use of an inexpensive and readily available catalyst, easy workup, improved yields, and the use of water as the solvent that is considered to be relatively environmentally benign.