This is a question that cannot really be addressed in a short response over the internet. If anything, this all ties into an old historical problem, which is usually referred to as the "Great Divergence."
The Great Divergence is named after a book written by Dr. Kenneth Pomeranz, where he examines how Europe overtook large established states in other parts of the world, including Mughal india, Qing China, and Tokugawa Japan, among others. The idea in question however is an old one, dating as far back as the 1800s when European historians speculated on why they were seemingly on top. What is new is the amount of work and research that has been done since then, which generally focuses along three lines of thought: what I would characterize as "inherentism," technology, and my pet theory (for full bias disclosure), the fiscal state.
Inherentism I would classify as the idea that something inherent in European (and later, the Japanese would argue, in the Japanese) peoples made them superior in some way to the other nations. Obviously this first manifested itself in pseudoscientific racism and Great Man theory, but some of its ideas to this day are still thought of and debated: for instance, the so-called Protestant Work Ethic by Max Weber discussed how Protestants are naturally harder working because of their belief (a cultural identity, in other words) and that was why the Protestant nations were outperforming the Catholic ones. However, these sorts of ideas have been challenged more and more recently, with most modern works examining historical data and concluding that rather than Protestantism being the direct source of economic growth, it was the increased literacy in Protestant areas-in other words, education, a factor that has been thoroughly demonstrated to be strongly correlated with economic growth-that was the primary factor.
Technology would be the second idea, that the Europeans had managed to get a hold of superior weapons and technology and that was what allowed them to succeed. The Scientific Method and the Age of Rationalism are usually mentioned in the same sentence, but it is important to note that many inventions up until the 1300s had originated from India or China, and that much scholarship was based out of the enlightened metropolises of the Middle East. Yet the apparent technological advantages of the East were not able to exert the same sort of political pressure on the West as the latter innovations of the Europeans: in fact contemporary accounts in the early colonial era demonstrate the utter disinterest the Asian empires had in European technology aside from their ocean-faring vessels and their muskets and cannon, some of which were acquired and utilized by these nations. But even as late as the 1700s the British were still borrowing technology from the East (the Congreve Rockets being one such example).
However, something we must consider in these contemporary accounts is ignorance. And one notable factor that we see omitted in Asian accounts is an understanding of European states and their fiscal policy. As DeSoulis mentioned, Asian governments were, by comparison to their European counterparts, extremely small and inefficient. They were typically very weak, the central government essentially offloading most priorities-from tax-collecting to national defense) to local provinces and the gentry. They also typically lacked a fiscal apparatus on the same levels of sophistication that the Europeans did. And this would result in financial weakness that they could ill-afford in times of crisis, from famine to invasion. And so you see numerous Empires collapsing from a financial crisis-the Ottomans, the Qing, and the Tokugawa being some of the more humiliating examples.
Where the Japanese succeeded was perhaps their unique circumstance of financiers: while many Asian nations either restricted or attempted to restrict their financiers (from prohibition of usury to general denigration of merchants in general) the Japanese feudalesque society was heavily reliant on merchants and lenders, such to the point that most feudal lords had working relationships with one or two merchants for most of their financing needs-in a sense, the feudal lord provided the political power for the "officially bottom rank" merchant, and the merchant provided the financial power to a feudal lord whose incomes were frequently impaired by poor weather and a shogun intent on crushing their financial strength in case of rebellion. The end result was that when the Tokugawa financial crisis came (spurred on by Western trade agreements, as was usually the case), the Meiji government already had a base of financial expertise-and most importantly, funds-that they could borrow from and utilize.
/u/DeSoulis talks about the relative strength of the Qing and Tokugawa governments, so I won't go into detail there. What I will mention is that from an economic point of view, the heart of Chinese economic activity-the Jiangnan region-was just as economically powerful as Meiji Japan or even most parts of Europe. So to argue that the Chinese economy was behind is not strictly true. What is more true is that the Qing government-and the Ming, for that matter-only collected about 5% of GDP worth of taxes, where other nations were collecting far more. So while the denominator may not have been all that different, the numerator was.
The end result was that the Meiji government-with its base of funding and its now empowered merchants as a base for industrial development-was able to both import foreign technology and also sell Japan as a modern country-the idea that Japan was just like the other European powers. Many Europeans had already been amiable to Japan-Japanophiles, or as some people may refer to them, "weeaboos," have been a concept for a long time-and the Japanese took no small amount of effort in comparing feudal Japan to medieval Europe. The apparent implementation of European institutions and technology in Japan further impressed upon the foreign visitors the "modernity" of Japan, although aside from the railroad and the enhanced state control it is rather questionable exactly how much of Japan had truly managed to modernize prior to World War II. The military victories that Japan had achieved over both China and Russia served to further enhance Japan's prestige as a modern country, although one would point out that China was even more behind than Japan was from a fiscal point of view, and that the Russian Empire was fighting a war with literally every diplomatic and logistical disadvantage possible.
In a sense, to finally answer your question, the success of Meiji Japan in mitigating European imperialism came in two forms. One was the superior fiscal and organizational ability of the Japanese state relative to larger but weaker empires like the Qing and the Mughals. The other was simply that the Japanese had managed to convince the Europeans that they were in fact modern, despite the fact that the society was still ultimately run very similarly to the feudal society that had supposedly been displaced. On the other hand, considering that suggests just how foolish their European contemporaries were to believe what I suspect to be a bit of a con job, perhaps they weren't so far behind the Europeans after all.
I cannot comment on other nations such as India or Persia, but here is a previous question comparing the industrialisationf of Japan and China
(u/lukeweiss) Why, in the 19th century, did Japan modernize so rapidly and successfully but China did not?
Here is a good answer by /u/DeSoulis
https://www.reddit.com/r/AskHistorians/comments/53pbe1/why_was_feudal_japan_able_to_quickly/
I'm going answer your question by summarising Marius Jensen's narrative on Japan's modern development in his 'The Making of Modern Japan.' I'm also going to mention the history and development of other Asian states. The reason is that this provides for a single unifying answer as to why some Asian states (Japan, Singapore, Taiwan) uniquely Westernised (and democratised) in very rapid fashion, whereas others did not.
In short, successful Asian industrialised countries did so under conditions of extreme geopolitical uncertainty. There was a specific reason why Japan confronted its own backwardness and accelerated its development to join the likes of 19th century Britain, Germany and France - it was due to the nation's fear of meeting the same fate as colonial China and India.
Japan's Opening to the World in the 1800s
In the early nineteenth century, Japan was more isolated and insular than ever (and in these times, isolation from the West meant isolation and ignorance from modern technology, trade and military tactics.)
This all began to change in 1838 when war broke out in China and the treaty of Nanking in 1842 forced China into a set of institutional relationships with the West known as the treaty port system. What this meant was that Western powers (in particular Britain), tired of its trade deficits, forceably opened up Chinese ports which would enjoy "protection" from the West. Naturally, this constituted a huge loss of sovereignty and national humiliation for China. This led to shock and crisis across the sea in feudal Japan. One official, Mizuno Tadakuni, who tried his damned best to reform the country, wrote “this concerns a foreign country, but I think it should provide a good warning for us.”
Japan’s military backwardness and China’s defeat seemed to leave little alternatives but to abandon Japan's policy of secluding itself to the West. The old order of Japanese isolationism and feudalism was unsustainable when confronted by the reality and crisis of colonialism and foreign affairs. This foreign crisis provided the fire for the overthrowing of the Tokugawa shogunate to rid Japan of the "evils of the past", with Japanese leaders moving to unify a divided and warring country.
The Meiji Revolution
In 1860s Karl Marx was telling his readers that Japan was the only remaining truly feudal state. But in 1890s, Japan was described as having centralised government and control far superior to China. Japan's change happened far rapidly than any other country in history and was fueled by a burning desire to join the "Great Powers" that had historically encircled Japan, restricted its sovereignty, and which signed unfair trading treaties with it.
Further, in Japan the ruling classes were not landowners themselves (like in European nobility), but held land in stewardship to the Emperor. If they were generously compensated (which they were), they could be asked to step aside and give way to measures needed to centralise power and develop a modern country. This was in stark contrast to in European states, where landowners enjoyed power and were a self-interested block to change. The Japanese Emperor was figurehead which the country saw as a unifying figure to head off the looming foreign threat.
The first step was to centralise the government. Landowners and barons, desperate to hold onto their positions, enthusiatically declaring their loyalty to the Emperor and allowed their holdings to be placed under central control.
The second step was to develop modern institutions. Nothing distinguishes Japan's Meiji period than its disciplined search for models throughout the world applicable for it to build up a modern country. There is no precedent for this - in 1871 to 1873, a delegation of fifty high-level Japanese officials circled the world on a training mission, visiting 12 countries, studying governmental organisation, industrial development, trade and modern education. The lessons were clear: Japan was entering a highly competitive world where victory meant learning from the best. Officials took what they saw as the best of American higher education, British industrialisation, French jurisprudence and German representative government - careful planning and hard work would bring Japan up to speed. A specialist bureaucracy, selected by merit, loyal to the emperor and removed from party politics and an elite cadre of senior statesmen, would see to the Emperor and the country's obsession with modernising the country.
By 1985, the Sino-Japanese War showed how much Japan had mastered the lessons American colonialists brought two decades earlier. Japanese gunboats forceably opened up Korean ports, ensuring Korea was open for trade and independent from Chinese influence. At this point, Japanese foreign affairs now centered on establishing a Japanese empire. And what really marked Japan's full and prestigious arrival into international society was the Anglo-Japanese Alliance in 1902 and the Russo-Japanese War in 1904, where Russia's entire Baltic fleet sailed 18,000 nautical miles to relieve Port Arthur, only to be sank in two days, with Russia than suing for peace. A generation ago, Japanese leaders were terrified of Britain doing to Japan what they had done to China - now, Britain was Japan's allies, as equals.
Other Asian States
What made Japan develop so rapidly was the external threat of Western colonialism which prompted leaders to overthrow the old feudal order and loyally look to the Emperor as a national figurehead, making a huge national effort to drive the country to modernity.
Academics call this "systemic vulnerability" - an severe external geopolitical threat which causes vested interests to work together and industrialise the nation and develop modern (democratic) institutions.
What about Taiwan? When Taiwanese leaders were pushed out of China, they had real fears of rural Maoist Communist revolution. The ruling Kuomintang had one choice if they wanted to politically survive - land reforms and putting all resources towards industrial development. A wealthy population and successful capitalist society doesn't turn to Communism.
What about Singapore? Separation from Malaysia in 1965 threw the country into major geopolitical limbo. Malay-Chinese racial riots and Britain's withdrawal of economic and military support led the leadership to model its country after Israel - also a resource-poor, geopolitically insecure country surrounded by its enemies which would accelerate towards industrialisation and solicit the international community (ie. America) for support and investment.
What about South Korea? Communist China and the North claimed to be the rightful sovereign of the South. So long as national reunification and Communist revolution was a threat, the government did everything to reform farming and improve rural productivity, solicit for American aid, and support its chaebols (Samsung, Hyundai, LG) in moving the country to an export-sophisicated modern country.
Summary
So in summary, what led Japan to industrialise so quickly? Well, it was Western colonialism. And the interesting thing is that of course Japan is one of the few Asian countries which was (comparatively) left untouched by the West in that it was never invaded by colonialists.
Sources
Marius Jensen - The Making of Modern Japan
Richard F. Doner, Bryan K. Ritchie and Dan Slater - Systemic Vulnerability and the Origins of Developmental States: Northeast and Southeast Asia in Comparative Perspective
There are multiple reasons why industrialization in Asia played out as it did. One way to look at it is that China, India, and Persia all possessed vital mineral or strategic resources. India in particular saw an influx in both Central Asian raiders from the north and the Europeans by sea. It was around the 15th century that the Portuguese had arrived in India and were building fortresses to secure the sea lanes. The Europeans had prior knowledge of the available resources and once they settled in India, their explorations revealed even more potential.
Effectively, the Europeans were able to setup self-sufficient colonies by drawing on the resources of the host country with military support from their home nations. Effectively what this meant was that the Europeans brought industrialization with them, setting up their own mechanized mills to directly compete with the local weavers. Japan, on the other hand, was able to import the technology and retool it to fit their needs, thereby driving indigenous innovation and technological refinement. Meanwhile, in India, the same technologies couldn't be imported since the British and French had engineered the total collapse of Indian political power, replacing it with their own. Without an indigenous government, the Europeans dictated what technologies were to be imported and which industries were to be developed. These were often support industries for their own developed industries back home.
This is one of the main points of nationalist historians in India. They point out the systematic deindustrialization of India by the British, which reduced the colony to a raw material supplier and finished goods market. Prior to the British, India possessed a thriving textile industry that fed the European markets. If these were allowed to develop without interference, the same technologies from Europe would have found their way to India, thereby fuelling the industrial process. However, the general attitude of the British towards India and their total control of the economy ensured industrialization would be very slow and cumbersome when it would finally take place years later as countries like India were starting off at 18th century levels with no support in the 1940s.
Edit: incorrect century of Portuguese arrival.
I'm not in a position to address the question from a more holistic angle, so I'll stick with what I know to be one factor nobody has really focused upon yet; namely their military-industrial buildup. Why? Because the ability to deter foreign intruders has always been heavily predicated upon the military ability to remove them if necessary.
Military technology in the late nineteenth century jumped along in fits and starts; with regular advances being made in most areas every decade or so. From about 1850 onwards, we consequently begin to see the world split into armament 'haves' and 'have nots'. That is to say, either you could (i) produce and develop the equipment your armed forces required domestically, or(ii) you had to rely on external sources. Those who fell into the latter camp grew increasingly dependent upon the former for their basic ability to defend their borders. Whilst purchasing arms potentially enabled a nation to keep up with other nations on paper (assuming you bought enough), the problem was that you also needed to ensure good diplomatic relations and close military co-operation with one of the former. Otherwise, supply could be cut off in a conflict, latest developments might not be transmitted, and you'd have no idea how to model your military institutions and personnel to effectively utilise the arms which you bought.,
Japan in this case was largely the only real success story in both instituting effective technological transfer of armaments technology, and also creating a sufficiently good linkage with a more advanced country to utilise what they had. If we look at South America, there are plenty of states who would purchase large quantities of top-quality arms from Europe, but very little in the way of attempts to become domestically independent of foreign supply. If we look at China or Turkey, some attempts were made, but were largely defeated by internal politicking and a lack of a coherent unified strategy.
Japan on the other hand sought to purchase everything it could, but simultaneusly reproduce production apparatus domestically. It also modelled its institutions upon what it considered to be the two best examples of such in the world; namely the British Royal Navy and the Prussian/German Army. Workers were sent abroad to learn production techniques, government funding flowed to newly established state arsenals and dockyards, and friendly personal relations were struck up with their selected role models.
The result was that Japan was able to to go toe to toe with a European naval power in the field by 1905. Whereas China continued to limp along and be considerably more vulnerable to any such conflict.*
*Note:- I'm not saying that there were no other factors (there are many I haven't touched upon), but this was a highly relevant one which nobody had yet really commented upon.
See for example, 'Technology Gatekeepers for War and Peace' by Miwao Matsumoto, 'Japan and the North East of England' by Marie Conte-Helm for some more technological/economic links to Japan, 'Rulers, Guns, and Money' by Jonathan Grant for the international arms trade, 'Kaigun' by Evans and Peattie for the Japanese Navy, and so on. There's also a few useful chapters in Volume 4 of 'The History of Anglo-Japanese Business Relations 1600-2000' ed. Janet Hunter & S. Sugiyama. For probably the best concise look at the armaments industry and the bearing it had on government, see Clive Trebilcock's 'The Vickers Brothers'.