SEATTLE — Over the years, Sonos has weathered competition from better known rivals like Apple and Bose to find a devoted audience among audio enthusiasts. But lately its wireless speaker has lost ground to an unexpected competitor, Amazon’s Echo.

Now it faces another challenge: a change in the corner office. After 14 years leading the company he helped found, John MacFarlane has resigned as chief executive of Sonos and has been replaced by one of his deputies, Patrick Spence.

Mr. MacFarlane, 50, has also left the company’s board of directors, though he will remain an employee to help mentor colleagues and work on other projects. He said he left the board so Mr. Spence would not feel like he was always looking over his shoulder.

Image John MacFarlane spent 14 years leading Sonos, a company he helped found. Credit... Sonos

“I don’t want to be that founder who’s always second-guessing,” Mr. MacFarlane said.

Sonos is a rarity among technology companies, started in 2002 at a time when independent hardware companies in consumer electronics, an industry dominated by much bigger players, were hard to find. Mr. MacFarlane did not take venture capital money for several years and kept the company private, shunning the usual routine of selling shares to the public or being acquired by a bigger company.