Eighteen months ago, Suhail Doshi vowed that Mixpanel Inc., the app analytics startup he co-founded, would be valued at $1 billion, making it what Silicon Valley calls a unicorn.

He nearly made it, securing a $65 million investment from Andreessen Horowitz that valued the company at $865 million.

But Mixpanel’s efforts to fuel rapid growth cost the startup, which is now struggling to regain its stature in a highly competitive industry. Its story reflects those of other startups seduced by a period of highflying valuations in a venture industry that is now cooling as investors write down investments and slow their deal pace.

To move forward, the 27-year-old chief executive of Mixpanel said he needs to forget about growth or fundraising and instead get the company’s spending under control.

Mr. Doshi and co-founder Tim Trefren dropped out of Arizona State University in 2009 and wrote software to help websites track users’ visits, clicks and conversions. Amid the recession they raised $12 million in seed and Series A funding from venture-capital firms Andreessen Horowitz and Sequoia Capital, as well as an elite list of angel investors. The company spent almost nothing on marketing but caught on with developers. It reached profitability in 2012.

In the fall 2014 Mixpanel had $22 million in the bank and didn’t need more money. But Mr. Doshi raised more anyway, telling The Wall Street Journal he wanted to “re-up the risk in the startup.”

Andreessen Horowitz wouldn’t give him the billion-dollar valuation he sought, but the near unicorn status stake came in higher than any of the half-dozen venture firms Mr. Doshi pitched. Sequoia Capital didn’t participate. A person with knowledge of the matter said the firm had a conflict due to another investment.

In a recent interview, Mr. Doshi said Mixpanel “could have pushed our investors” to value it at $1 billion in 2014. “We really kind of just realized that at the end of the day, that was just ego getting in the way of things.” At that time, there were 79 private companies valued at $1 billion or more by venture-capital firms world-wide, according to The Wall Street Journal and Dow Jones VentureSource.

Like many unicorn hopefuls, Mixpanel sacrificed profitability for growth. During 2015 and 2016, Mixpanel planned to triple its sales staff, open offices abroad, acquire machine-learning startups and develop new analytics products for sales and finance, according to the pitch deck it used to raise the Series B.