KULIM, Malaysia — Tucked away in this former tin-mining town, past the small farms of banana trees and oil palms, is one of the solar industry’s best-kept secrets.

The six factories here with cavernous rooms up to one-third of a mile long constitute the production backbone of First Solar. Working alongside minivan-size robots adapted from car assembly plants and other industries, 3,700 employees produce five-sixths of the American company’s solar panels. Workers in Ohio make the rest.

The list of manufacturers is long. Panasonic of Japan has a solar panel factory a mile down the road. SunEdison makes wafers 60 miles away in Chemor. Hanwha Q Cells and SunPower have giant factories even farther south, while Solexel, a Silicon Valley start-up, is preparing to build an $810 million solar panel factory in stages.

Malaysia, a Southeast Asian nation with just 30 million people, is the biggest winner in the trade wars that have embroiled the solar sector. As Chinese companies have been hit with American tariffs and European quotas, Malaysia has increasingly attracted multinationals with its relatively low labor costs, lucrative tax breaks, warm relations with the West and abundance of English-speaking engineering talent.