Marissa Mayer, one of Google's top executives and its first female engineer, will be the next chief executive officer of Yahoo, making her one of the most prominent women in Silicon Valley and in corporate America.

Mayer will start immediately, with her first day being Tuesday 17 July. The fact that she was a candidate had been kept completely secret – with no indication from Google's top managers that she was about to leave.

The appointment of Mayer is a surprising and impressive coup for Yahoo, a company that has been racked by internal turmoil as it has struggled to compete with Google, Facebook and Twitter in the online display advertising market. Mayer will be Yahoo's fifth chief executive in five years, and its second woman.

"I am honoured and delighted to lead Yahoo, one of the internet's premier destinations for more than 700 million users," Mayer said in a statement. "I look forward to working with the company's dedicated employees to bring innovative products, content, and personalized experiences to users and advertisers all around the world."

Yahoo said that Mayer's appointment "signals a renewed focus on product innovation", indicating that the company aims to compete on the technological – and not just the content – front.

Mayer, 37, has a degree in artificial intelligence. In 1999, when Google was barely a year old, she became its 20th employee, going on to spend 13 years there. She had become one of its most prominent voices. More recently, Mayer has also begun to forge a wider role in corporate America, recently joining the board of retail giant Walmart.

She is six months pregnant with her first child, due in October, and said her maternity leave would be "a few weeks long and I'll work through it".

Mayer joins a very short list of women in top jobs in Silicon Valley, alongside Meg Whitman, the chief executive of Hewlett-Packard, Virginia Rometty, the head of IBM, and Sheryl Sandberg, Facebook's chief operating officer.

She takes over at a company that has been roiled by scandal and argument. In May, Yahoo lost its last chief executive, Scott Thompson, after only four months. The former PayPal boss was ousted after it emerged that he had padded his resumé, leading to angry shareholders demanding that he go. Thompson's departure also led to a board reshuffle and the resignation of chairman Roy Bostock.

Thompson's exit followed the even more tempestuous firing of his predecessor Carol Bartz, who left in a foul-mouthed tirade, calling the board "doofuses" who had "fucked me over."

Yahoo has struggled for years to keep up with Google in search ads as Facebook has eclipsed it in display advertising. Yahoo is now worth just over $19bn, less than half the $44.6bn Microsoft offered for the company in 2008.

The company stock jumped 2% in after-hours trading to just over $16.

Colin Gillis, a tech analyst at BGC Partners in New York, said Mayer was a great appointment and a loss for Google. "She is in a different league," he said. "She is very widely respected and she really knows this business."

At Google, Mayer had been responsible for many of the company's key products, including its famous search homepage, Gmail and Google News. More recently, she has taken on responsibility for location and local services, including Google Maps.

She was a popular Google prosleytiser, often sent out to talk about Google's services, and she also sat on Google's operating committee, a cadre of close advisers to Google's co-founders, Larry Page and Sergey Brin.

Shortly after her move into local services in 2010, Google made another executive, Jeff Huber, senior vice-president of local and commerce, one level above Mayer's post.

Gillis said she Mayer's career path appeared to have been blocked at Google. "I think she got so far but they were moving her sideways," he said. "I don't think they will be happy about this. It's a blow."

Yahoo co-founder David Filo said: "Marissa is a well-known, visionary leader in user experience and product design, and one of Silicon Valley's most exciting strategists in technology development. I look forward to working with her to enhance Yahoo's product offerings for our over 700 million unique monthly visitors."