The first stage of the reaction is simple
tautomerism
.
The final step of this reaction follows the
E2
reaction mechanism.
Intramolecular
reaction is, of course, vital to the heterocycle formation.
The same starting material can be used to form
pyrroles
or
thiophenes
.
References:
Amarnath V.; Amarnath K.; Journal of Organic Chemistry, 1995, Volume 60. Issue 2, 301-307
Minetto G.; Raveglia L.F.; Taddei M.; Organic Letters, 2004, Volume 6, Issue 3, 389-392