The earliest people in Japan probably brought with them ancient religious ideas from Africa. They used red ochre to bury dead people, for example. By the time Japanese writers wrote books describing their religion in the 700s AD (the Kojiki and Nihon Shoki), these early ideas had developed into Shintoism. Like everyone else in the world at this time, Japanese people sacrificed to and worshipped a bunch of gods. Each god represented some powerful force: the weather, the ocean, childbirth, love, death, etc.
Even before the Kojiki, though, in the 500s AD, missionaries from Korea brought a new religion to Japan: Buddhism. Buddhism came originally from India. Then many people became Buddhists in China and Korea. By 587 AD, the Yamato court had officially become Buddhists. This was a time when China’s Sui Dynasty and Korea were both very influential in Japan. So Buddhism came to Japan along with many other Chinese things – paper, fans, printing, Chinese writing, wooden temples – and also Korean things like horses.
About 1200 AD, when the shoguns took power in Japan, people became more interested in Zen Buddhism, which had already been around since 500 AD in China. Without the big empire that encouraged people in Iran and China and Rome to choose a unified religion that could stand up to the Emperors, people in Japan didn’t feel the need to abandon their old gods. Most people in Japan just combined Buddhist and Shinto worship. They didn’t feel any need to choose between them.