Sometime around the invention of agriculture, the cats came crawling. It was mice and rats, probably, that attracted the wild felines. The rats came because of stores of grain, made possible by human agriculture. And so cats and humans began their millennia-long coexistence.
This relationship has been good for us of course—formerly because cats caught the disease-carrying pests stealing our food and presently because cleaning up their hairballs somehow gives purpose to our modern lives. But this relationship has been great for cats as species, too. From their native home in the Middle East, the first tamed cats followed humans out on ships and expeditions to take over the world—settling on six continents with even the occasional foray to Antarctica. Domestication has been a fantastically successful evolutionary strategy for cats.