Was slavery the result of racism or was racism the result of slavery?

People of held slaves for thousands of years. Usually, the slaves were the same race as the owners.