Answer by Makiko Itoh, 海外組:
Well, they were basically forced to. Or rather they did not see much choice in the matter. However, there was still strong opposition to doing so, which led to a brief civil war and a total change of government.
Japan was not totally unaware of advances in Western technology, since they had ongoing contact with the Dutch even during their period of isolation. But when the black ships (what foreign vessels were called) showed up on their shores, especially U.S. Commodore Matthew Perry's fleet in 1853, to ask (or demand) that Japan open its ports to trade and restocking of ships from other countries, it was a huge shock to many people just how advanced the technology was, especially in shipbuilding and weaponry.
This is a contemporary document illustrating Perry's fleet.
The government in power, the Tokugawa shogunate, was still opposed to opening up the country. They were eventually overthrown (although a lot of bloodshed was avoided when the last shogun resigned voluntarily), and the Meiji government took over.
One factor in the decision to very rapidly Westernize the nation, in terms of technology and in things like clothing and eating habits, was to try to convince the Western powers that the Japanese were their equals. They were very much afraid of ending up like China, dominated and divided among various Western colonial powers. So they urged the citizenry to adopt Western mannerisms and even morality as quickly as possible, as a kind of civic duty.
I have answers addressing this period in Japanese history in more detail.
Incidentally, the current NHK historical drama Yae no Sakura is about this period, if you can catch it somewhere. It's pretty good.
More questions on History of Japan: