There is an interesting passage in Steven Pinker’s The Blank Slate in which he argues that the Nazi and Marxist ideologies share important ideological assumptions that partly explain why each produces large-scale human suffering:
The ideological connection between Marxist socialism and National Socialism is not fanciful. Hitler read Marx carefully while living in Munich in 1913, and may have picked up from him a fateful postulate that the two ideologies would share. It is the belief that history is a preordained succession of conflicts between groups of people and that improvement in the human condition can only come from the victory of one group over the others. For the Nazis the groups were races; for the Marxists they were classes. For the Nazis the conflict was Social Darwinism; for the Marxists, it was class struggle. For the Nazis the destined victors were the Aryans; for the Marxists, they were the proletariat. The ideologies, once implemented, led to atrocities in a few steps: struggle (often a euphemism for violence) is inevitable and beneficial; certain groups of people (the non-Aryans or the bourgeoisie) are morally inferior; improvements in human welfare depend on their subjugation or elimination. Aside from supplying a direct justification for violent conflict, the ideology of intergroup struggle ignites a nasty feature of human social psychology: the tendency to divide people into in-groups and out-groups and to treat the out-groups as less than human. It doesn’t matter whether the groups are thought to be defined by their biology or by their history. Psychologists have found that they can create instant intergroup hostility by sorting people on just about any pretext, including the flip of a coin.
The ideology of group-against-group struggle explains the similar outcomes of Marxist and Nazism. (p.157 paperback, emphasis mine)
To me, the key corrective to the excesses of any ideology that tries to build utopias is to recognize that human thinking and planning are flawed, and that we must respect the welfare and rights of individuals. We should not become so convinced in the rightness of our cause that we become willing to utterly trample others in order to achieve it. Even when confronted with hostile ideologies which we cannot tolerate, we should not be ruthless toward our opponents. Rather, we should consider the extent to which the aims we are seeking to achieve justify the means through which we are seeking to achieve them. We should also bear in mind the possibility that we are wrong or misled, and design systems of government to limit how much harm governments themselves can do.