Structurally diverse pyrroles, indoles and imidazoles bearing an N-ω-azidoalkyl moiety and an aldehyde or ketone function were prepared and successfully introduced into in situ imine generation via the intramolecular Staudinger/aza-Wittig tandem reaction. Reduction of the generated imines led to medicinally relevant nitrogen-containing fused heterocycles such as tetrahydropyrrolo[1,2-a]pyrazines and diazepines. Rare 8-membered hexahydropyrrolo[1,2-a][1,4]diazocine and 9-membered dihydro-4,8-(metheno)pyrrolo[1,2-a][1,4]diazacycloundecine were also synthesized. In addition, several one-pot transformations involving cyclic anhydrides or isocyanides (Castagnoli-Cushman, Ugi and azido-Ugi reactions) were added to the Staudinger/aza-Wittig sequence to afford novel fused polyheterocyclic delta-lactams, cyclic bisamides and tetrazoles in a multicomponent fashion. The synthesized compounds were profiled against human Trace Amine-Associated Receptor 1 (hTAAR1), and the best performing compound showed low nanomolar agonistic activity with an EC50 of 0.025 μM. © 2024 The Royal Society of Chemistry.