Anpan was first made in 1875, during the Meiji era, by a man called Yasubei Kimura, a samurai who lost his job with the rise of the Imperial Army (made up of conscripts) and the dissolution of the samurai as a social class. The Meiji era was a period in which Japan was becoming increasingly westernized, and many samurai who lost their jobs were given work that was totally new to them. The Western role of baker was one such job.
One day, while wandering around the area where many people employed in Western jobs worked, Kimura Yasubei found a young man making breads. Yasubei felt that it was time for Japanese culture to become more Westernised, and so he started a bakery named Bun'eidō (文英堂). In the next year he moved to Ginza and renamed the bakery Kimuraya (木村屋). At that time, however, the only recipe for bread known in Japan was for making a salty and sour tasting bread, ill-suited to Japanese tastes at the time. Yasubei wanted to make a bread that was more to Japanese tastes. Finally, he figured out how to make bread in the way of the Japanese manju -- raising the dough with the traditional sakadane liquid yeast. He then filled the bread with a bean paste wagashi and sold anpan as snacks. Anpan was very popular, not only because of its taste, but also because the Japanese were interested in anything new and foreign at this time.
Later, a man called Takayuki Yamaoka, a chamberlain of the Meiji emperor, who loved anpan, asked the Tokugawas, the rulers of Japan before the Meiji Period, to present anpans to the emperor when visiting him. So the Tokugawas asked Yasubei to make some for the emperor. Yasubei worked hard to make the anpan and, because he also cared about their appearance, he decorated them with a salt-pickled sakura in the middle of each bun. This anpan was presented to the Meiji emperor on April 4, 1875. The emperor told Yasubei to present him the Anpan everyday, and because of the rumor that the emperor ate anpan, breads, and especially anpan, began spreading around the country.