http://revach.net/article.php?id=5124

Section: Galus & Geula   Category: Moshiach
What Comes First Moshiach or the Bais HaMikdash?

In Shmoneh Esrei in the bracha of V'Lirushalayim Ircha we daven for Hashem to return us to Yerushalayim and build the Bais HaMikdash. We also include a petition of "V'Chisei Dovid Avdicha Miheira L'Socha Tachin", that Hashem should restore the throne of Malchus Bais Dovid. Why then do we have a separate bracha right after that "Es Tzemach Dovid", specifically asking Hashem to restore Malchus Bais Dovid, isn't this repetitive?

The Ein Eliyahu answers that there are two ways for the Geula to come about. If we are not on a high madreiga, first we will build Yerushalayim and the Bais HaMikdash. Only after that will Moshiach come and lead us. However if we merit an immediate redemption through our good deeds, then Moshiach will come immediately, even before any rebuilding takes place.

Therefore in the first bracha we ask Hashem for Yerushalayim, the Bais HaMikdash, and Moshiach in that order. After that do we ask Hashem to have mercy on us and send us a speedy redemption to send Moshiach immediately, even before the city or the Bais HaMikdash are built.