High yield solvent-base-controlled, transition metal-free synthesis of 4,5-functionalized 1,2,3-thiadiazoles and 1,2,3-triazoles from 2-cyanothioacetamides and sulfonyl azides is described. Under diazo transfer conditions in the presence of a base in an aprotic solvent 2-cyanothioacetamides operating as C-C-S building blocks produce 5-amino-4-cyano-1,2,3-thiadiazoles exclusively. The use of alkoxide/alcohol system completely switches the reaction course due to the change of one of the reaction centers in the 2-cyanothioacetamide (C-C-N building block) resulting in the formation of 5-sulfonamido-1,2,3-triazole-4-carbothioamide sodium salts as the only products. The latter serve as good precursors for 5-amino-1,2,3-thiadiazole-4-carboximidamides, the products of Cornforth-type rearrangement occurring in neutral protic medium or under acid conditions. According to DFT calculations (B3LYP/6-311+G(d,p)) the rearrangement proceeds via intermediate formation of a diazo compound, and can be catalyzed by acids via the protonation of oxygen atom of the sulfonamide group.