A chemoselective approach was developed for the synthesis of highly functionalized oxazoles and benzofurans using an intramolecular Wittig reaction as the key step. By choosing proper trapping reagent or method of addition of reagents, chemoselectivity can be controlled toward either oxazole or benzofuran derivatives.