Ignorance and a lack of empathy for humanity (including ourselves) is what caused racism to occur. We cannot hate others if we truly value ourselves and mankind. In addition, judging others because of their race shows a real lack of knowledge with regard to what makes individuals important. This seems especially ironic since most people are an amalgamation of different races, heritages, or etc.
That is an impossible question to truly answer. I would argue (but I cannot prove) that racism started when Europeans first met black Africans. The racism started because of how the Africans looked and their level of technology. The racist attitudes came to America with the Europeans and were strengthened by slavery.
I think that Europeans looked at Africans and thought they were inferior. The Africans had low levels of technology and they looked very unlike the Europeans. Because of that, the Europeans figured that they were "backward" due to their race/looks.
When slavery became so important in America, that only made things worse. Whites looked down on blacks because slavery made it both necessary and possible to do so. If you're going to enslave a whole race of people, you need to think they're inferior. And if you only see them as slaves you're going to think that there's something inferior about them.