The 4-oxoalkyl- and 4-iminoalkyl-5-azidothiazoles undergo a ringtransformation with nitrogen loss at relatively low temperatures to afford 4-cyanooxazoles and 4-cyanoimidazoles, respectively. The mechanism, which is thought to involve a ring opening-ring closure process, is discussed.