The ideological transformation of Germany and Japan seems to have been so quick, painless, and complete -- but seventy years later, the idea that you could impose liberal democratic institutions via military occupation seems absurdly naive.
Why was there no meaningful fascist (or at least nationalist, or anti-occupation) insurgency in either country? How did the Allies convince the German and Japanese people to repudiate the ideology that had inspired such fanatical zeal during the war?
I think you have to seriously consider the effect of the World Wars on the national psyche of the defeated powers, especially Germany. Ive studied German rearmament in the Cold War, and a major theme which came up over and over was this idea of "Not again." And think about it, in the 31 years between 1914 and 1945, Germany went to war twice. Millions of young men died, Europe was torn apart, and Germany was politically, economically, and spiritually broken. A person who was 18 in 1914 and served in the "Great War" would have only been 49 by the end of the next war.
So Fascism, Nazism, Monarchism, and Prussian Militarism in general all became linked with these great defeats. In 1950, Germany was split, disarmed, and controlled by the Allied Powers. Germans didnt need much convincing to see how their actions had brought them to that position.
And then you have to work in the horrors of the Holocaust, and how the Jewish extermination affected the German people. Many had supported, either directly or indirectly, the Nazi state. Over 30% of Germans had voted for them in 1933, and millions had served in their army and government apparatus. Thousands more had informed on their neighbors, business partners, and friends to the Gestapo. And as a result of this Fascist feaver, millions of Jews and others were killed in the camps. Even more were imprisoned and forced into slavery in the worst conditions imaginable. After the extent of the Holocaust became known, it didnt take much to convince the German people that Nazism and Fascism were wrong.
If youre interested in reading more on this topic, I think Konrad Adenauer's memoirs are actually pretty interesting. He was the first Chancellor after the fall of Nazi Germany, and he faced the challenge of putting Germany back together again. He had to rebuild a Germany when people still feared what Germany had been, and had to do it within this new framework of the Cold War. Its all very interesting and deals, in part, with this whole subject. I have a lot of respect for Adenauer.
As for Japan, Im less clear on. But I would also point out that things are not so cut and dry. They did not (and have not) abandoned their wartime heroes the way Germany did, and it's still a huge problem even today.
I'm not an expert on the time period (as I merely studied history teaching, not actual academic history), but I want to interject that the question whether Denazification was in fact successful, and how successful it really was, is still very much up for debate among German (and Austrian!) historians.
Given the amount of people employed in the direct or indirect support of the Nazi state during the war (be it as active Nazis, bureaucrats, snitches, party functionaries, or just loyal supporters), the Allied Denazification campaigns only reached a small part of the population involved in the Nazis' crimes, and many former party members, particularly academics and military men, were quickly re-integrated and re-established in their former professions.
This was even more pronounced in Austria, which quickly re-integrated even war criminals like Heinrich Gross into academia and state apparatus.
One should also be careful of mixing up the attitude of trained historians with those of the general population, which had a much less harsh view on certain parts of the Nazi apparatus than is commonly held among academicians. Particularly the Wehrmacht was long thought of as a relatively "clean" and "umblemished" part of the Nazi apparatus, and an exhibition in Germany that aimed to revise that popular image was controversial among the general population at the time (though not unwelcome among historians).