SAN FRANCISCO — Marissa Mayer, chief executive of Yahoo, said on Tuesday that the Internet company would spin off its 15.4 percent stake in Alibaba, China’s leading e-commerce company, into a separate company.

The decision, which Wall Street has been waiting for since Ms. Mayer joined the company in 2012, cheered shareholders because they will directly reap all the remaining profit from Yahoo’s prescient investment, which cost almost nothing a decade ago but is now worth about $39.5 billion.

In the process, Yahoo will avoid any taxes on the transaction but will be stripped of its single most valuable asset. The Alibaba stake alone now makes up nearly 85 percent of Yahoo’s market value.

Resolving the Alibaba question now turns the spotlight on Ms. Mayer’s plans to turn around Yahoo’s core Internet advertising business, which has dealt with years of declining revenue as advertisers and Internet users switched their money and attention to flashier, more innovative services from competitors like Google, Facebook and Twitter.