Joseph and his brothers prospered and so did subsequent generations, until Egypt had a large population of sojourning Hebrews.
Eventually a Pharaoh developed a prejudice against the Hebrews. He didn’t really know how they came to sojourn there or that Joseph had been good friends with some previous Pharaoh, only that there were a lot of Hebrew “immigrants.” So Pharaoh made it a policy to make Hebrews second class citizens–more or less slaves forced to do hard labor like construction in an era without power tools or backhoes. Pharaoh hoped that the hard labor would increase the mortality rate and take care of the problem. But Pharaoh’s plan backfired because instead of dying off, the Hebrew population increased–probably because sex was one of the few pleasures in life for slaves in the Bronze Age. Or maybe their population didn’t actually increase, but Egyptian xenophobia and racism magnified the population in the popular imagination. Anyway, Egyptians increasingly oppressed and overworked the Hebrews.
Finally, Pharaoh issued an official policy of genocide, ordering the two Hebrew midwives Shiprah and Puah to kill all male infants they delivered. (Girls were spared because their future babies would be whatever ethnicity the man who impregnated them was). However, the midwives had no desire to murder babies, so when Pharaoh confronted them about why there were so many male babies around, they claimed that Hebrew women delivered before they could even get there, so they had no chance to murder babies in secret. So Pharaoh went public with his genocidal policy and made it the law of the land for Egyptians to kill any male Hebrew babies they came across.