What is the reaction mechanism of a 5-endo-trig cyclization?
Your mechanism to the 5-endo-trig product (4) is very close.  Notice however that when you do the initial cyclization, the intermediate formed has a positive charge on nitrogen along with the negative charge on oxygen (as you showed).  This cyclized intermediate then just needs to move a proton from the nitrogen to oxygen to form the neutral enol which then converts to the (ester) carbonyl - which is your desired product.  No other reagents are required.