What are the various factors that contributed to the rise of the political party Alternative for Germany? Why has it gained popularity?
The "Alternative für Deutschland" (AfD) was founded in 2013 as a reaction to the billions of euros transferred to Greece (to prevent a Greek bankruptcy and have an impact on the whole euro-zone).
The founders (lead by Bernd Lucke) founded the AfD as kind of anti-euro-currency-party. Since a lot of people disagreed with the governments decision to rescue the Greek partners they had quite a lot popularity in the beginning (but since German voters are quite reserved, this was not enough to get something like a majority. They managed to get into 12/16 state parliaments (2014). That is impressive for a new party, since the aren't that many new parties in Germany.
Bernd Lucke had, beside the anti-euro-currency-thingy, lots of liberal ideas (with a nationalistic touch) and filled the gap the liberal party FDP has left (besides that the CDU, Germany's governing party, moved to the middle of the political spectrum, so there was a gap as well). The right wing of the AfD overthrew Lucke and since the refugees came to Germany there was another hot topic for the AfD to gain votes from frightened or worried voters.
Furthermore they completed their program with things like no gay marriage, no gay adoption and so on.. So they ended up at the very right part of Germany's political spectrum. They gained votes too, because lot of people wanted to show established parties their disappointment (don't as me how this could help).
Now they are between 6 and 20% in the different parliaments (16/16) (2017). They will most likely join the Bundestag in autumn. Overall you can see a decrease of popularity, because people realized Angela Merkel managed most of it quite okay and the CDU recently became a little right-orientated again.