There were two main factors that led to the erosion of the Tokugawa Shogunate and the Meiji Restoration. First, there was the rise of the merchant class and the decline in the power of the samurai that came with it. Second, there was the pressure from the West, epitomized by the "opening" of Japan by Commodore Perry.
As the Tokugawa era came to a close, the merchant class in Japan had become very powerful. They were very rich and the samurai class depended on them for money. This went against the formal hierarchy in which merchants were the lowest rung. This disparity between the formal system and reality eroded the foundations of the Tokugawa government.
Second, the intrusion of the West, in the form of Perry, severely shook the foundations of Japanese society. The country, which had thought itself superior and invulnerable, was badly shocked by the fact that the West was stronger than Japan. This led to political upheaval as various factions pushed for various different solutions to the issue.
Overall, then, Japan's feudal society had been eroding for some time. When Perry "opened" Japan, the structure of Tokugawa government was given a push and its eroded foundations were revealed. This led to the fall of the Tokugawa and the Meiji Restoration.
Commodore Perry's arrival in Japan in 1853 resulted in factors that led to the collapse of the Tokugawa Shogunate. The opening up of Japan to western trade sent economic shockwaves through the country, as foreign speculation in gold and silver led to price fluctuations and economic downturns. In addition, domestic industries collapsed after facing international competition, and the Japanese economy was in dire straits as the Japanese faced high unemployment.
In this atmosphere, the Shogun, then the leader of Japan, invited the daimyo, or the local feudal lords, to a Council of State, setting up an opportunity for them to rebel. The shogunate, a system of feudal lords called daimyo, had been unstable for years. The samurai, or warrior class, had little reason to exist after the Tokugawa pacified Japan. The farmers under this system, who had to pay a 50% tax on their crops to support the shogun and the daimyo, were restive. The stage was set for rebellion.
After the shogun signed treaties with foreigners, many nationalist Japanese, particularly those in the provinces of Satsuma and Choshu, felt the shogun should be replaced, as they felt he was powerless. The anti-foreign sentiment was directed against the shogun as well as against foreigners in Japan. The Satsuma and Choshu clans united to bring down the shogun, and in 1867, they did so. In the following year, they restored the emperor, Meiji, to the throne in the Meiji Restoration. During this period of the Meiji Restoration, Japan rapidly modernized and became a military power.