There are three keys to TSMC's success: Specialization, Diversification, and Volume. These are the keys of the foundry model and TSMC is the king of the Foundries. First, by specializing only in manufacturing, rather than semiconductor design, TSMC was able to really focus on making their manufacturing process consistent, reliable, and efficient. When TSMC was founded, back in the 1980's, most of the leading semiconductor companies made their own designs. This left them vulnerable because they had to produce both a successful design and a successful manufacturing process. Any slip ups in either area, would cause them to be overtaken by the competition. They also had to worry about such things as 3rd party software support, marketing, standards adoption and so on. In other words, there was an entire landscape of potential landmines that TSMC (and UMC, which was bigger at the time) avoided by means of their business model.
The early TSMC processes were not particularly competitive. They focused on delivering older tech nodes, but at reduced costs. Cheap labor and government support were key for cost reduction. This allowed them to attract a number of customers, which brings up the next key, Diversification. Early customers tended to be established semiconductor companies like Motorola, Texas Instruments, and Phillips (NXP), which were more than happy to transfer their older designs to TSMC in order to free up their leading edge fabs for newer designs. Throughout the nineties this gave TSMC experience in transitioning from node to node across technologies. Often their customers would even help them make advances, since they were still a few nodes behind and not considered a competitive threat. As TSMC's manufacturing prowess improved, they attracted fabless companies like Qualcomm, Broadcom, MediaTek and so on. Here, they had a clear advantage, since the fabless companies would rather work with a pure-play foundry than have to go to one of their competitors for production services. The Fabless/Foundry model enabled the fabless companies to become more successful, which in turn ramped up the number of such companies, contributing to the customer diversification. Of course, some fabless companies failed, but now there were enough that some would always be successful, which essentially guaranteed TSMC a diverse supply of successful customers, and immunized them against a design flop.
The success of fabless companies really exploded in the early 2000's, allowing TSMC to grow and achieve major volumes, the final key to their success. Fabs are extremely expensive, but the cost per wafer drops significantly as the fab gets bigger. Thus, with huge volumes come reduced production costs and ultimately, large profits. TSMC built giant fabs and became the low-cost leader. This left TSMC in the right place at the right time to capitalize on the emergence of the Smartphone, a huge market for their products. Smartphones also provided an application that would benefit from advanced technology nodes.
In the early 2000's Texas Instruments made the strategic decision to bow out of advanced node development and transferred their 90nm process to TSMC. In 2003 TSMC participated in the Crolles 2 Alliance with Phillips, ST Microelectronics, and Motorola to develop a 65nm process on 300mm wafers. By 2006, while they still trailed technology leaders like Intel and IBM, the gap had closed significantly. During this time Intel was not sitting on its laurels, in 2007 they introduced a "Replacement Metal Gate/High-K" process at the 45nm node, an achievement that astounded the rest of the industry, which had focused on and struggled with a "gate-first" high-k strategy. IBM and partners like AMD and Sony, were left at a significant disadvantage and were only able to close the gap with IBM's 32nm node in 2010. Around this time, TSMC focused on a fast follower strategy, essentially reverse engineering Intel's chips and copying their strategy as quickly as possible. By 2011, they were able to release a 28nm technology that has perhaps been their most economically successful node to date. This left them able to invest significant sums of money in future development, setting them up to catch up to and then surpass Intel.
In 2012 Intel made another huge leap by introducing finfets at the 22nm node. Samsung, Globalfoundries, and TSMC all copied Intel, releasing so-called 14nm or 16nm nodes that were closer in performance to Intel's 22nm node in 2014/15. While inferior to Intel's 14nm node, Globalfoundries' technology was good enough, to enable AMD's superior "Zen" design to give Intel a serious run for its money. AMD gained market share and the race was on for a 7nm finfet process. Similarly, TSMC's 16nm process was competitive enough to enable Nvidia's GPU's to make serious inroads on the supercomputing and high-performance-computing front. Strengthening competition as well as softening demand for personal computers in the smart phone era, meant that Intel faced some serious headwinds. In 2016, TSMC released a 10nm technology that was more or less at parity with Intel's concurrent 14nm process. Intel struggled to release it's own 10nm node, by 2018 they were able to produce some low power 10nm chips for laptops, but they weren't able to yield the more profitable high performance server chips. Meanwhile, TSMC took the technology lead with their 7nm process introduced at the end of 2018. Since then, Intel has seemed to stall, they are only now ramping production of desktop CPUs on their 10nm process. TSMC has continued to make progress with 5nm currently in production and 3nm to be released soon. IBM dropped out of manufacturing in 2015, but have partnered with Samsung on R&D and have a 2nm process in the works, which should keep things interesting. Meanwhile, Intel is refocusing and will hopefully get back into the game soon, although they are also gearing up to use TSMC for some of their production.