Before Moshiach comes, we are taught in Torah, that there is a war of Gog and Magog. There are many different facets to this and many ways the Rabbonim have interpreted this war to be.  It is not an actual physical war between nations.

Chassidus explains that the war of Gog and Magog is the stream of foreign thoughts that run through our minds all day, including thoughts of worry, fear and anxiety.  On Shabbos we rest from the war of gog and magog, and  we rest from these  foreign thoughts, similar to Moshiach who will bring peace to the world.

Perhaps this is also why, at the end of days we must destroy Amalek. Amalek, according to Chassidus and Kabbalah, is the idea of doubt. Amalek is a physical nation as well and when Moshiach comes we will know which nation is Amalek to destroy it, but  on a spiritual level Amalek is doubt.  Anything that brings doubt to us, or doubts to our faith, causes anxiety.  Therefore,  the two are connected: getting rid of Amalek spiritually, and winning the war of Gog and Magog.