BEIJING— Apple Inc.’s once unlimited prospects in China ran headlong into an increasingly perilous landscape for Western companies here as regulators in the world’s No. 2 economy handed the tech giant the latest in a series of setbacks.

Shenzhen Baili, a little-known startup, won a surprise injunction against sales of Apple’s iPhone 6 and iPhone 6 Plus in Beijing, based on a patent covering smartphone design. Apple said the order had been stayed pending appeal and sales remain unaffected.

The ruling is a hint of the growing challenges that Western companies are facing here, as Chinese companies mature into stronger competitors and regulators increasingly insist that foreign firms play by Beijing’s rules.

As a company geared to consumers and one of China’s favorite brands, Apple has long seemed immune from the scrutiny focused on makers of more sensitive equipment like servers and routers. Industry watchers mused over Apple’s ability to sell mobile content while other foreign companies couldn’t. Many chalked it up to Chinese officials’ love for iPhones.

But under President Xi Jinping, China has taken a stricter view of technologies and content that it previously gave wider berth.