Moshe's final mission is revenge?!

In this week's parsha (Torah portion), we find the last mission Hashem gives Moshe (Moses) - to avenge what Midian did to Am Yisrael (the People of Israel).

This is a very odd "final mission" for Moshe: First of all, we know revenge is something we are usually forbidden to do, but especially Moshe, whose family is from Midian and spent so many years there, owes them much gratitude. So why is he chosen for this mission, and more importantly, why is the last mission of his life??