After Japan opened up to the West following U.S. Commodore Matthew Perry's visits in 1853, its political situation gradually became more and more chaotic.
The country was divided along various lines of political opinion; one of these schools of thought (which had existed prior to Perry's arrival) was sonnō jōi: "Revere the Emperor, Expel the Barbarians."
Radical followers of this ideology began to commit acts of murder and violence in Kyoto, the imperial capital.
In 1863, hoping to respond to this trend, the Tokugawa Shogunate formed the Roshigumi (浪士組), a group of 234 masterless samurai (rōnin), under the nominal command of the hatamoto Matsudaira Tadatoshi and the actual leadership of Kiyokawa Hachirō (a dynamic ronin from Shonai).
The group's formal mission was to act as the protectors of Tokugawa Iemochi, the 14th shogun, who was preparing to embark on a trip to Kyoto.
The Rōshigumi, was funded by the Tokugawa regime. However, Kiyokawa Hachirō's goal, which he revealed following the group's arrival in Kyoto, was to gather rōnin to work with the imperialists.
In response, thirteen members of the Rōshigumi became the thirteen founding members of the Shinsengumi