Alphabet Inc said on Tuesday it would buy back $70 billion in stock and posted first-quarter profit and revenue above estimates as demand rose for cloud services and ad sales held up better than expected.

Investors cheered the buyback plan, sending shares of the Google parent as much as 4% higher in after-hours trade before they pared gains to trade up 1.6%. Demand rose for cloud services and Google's ad sales held up better than expected.

Alphabet reported a slight dip in first-quarter ad sales from a year earlier to $54.55 billion, which nonetheless beat analyst estimates of $53.71 billion. It was the third such decline for the company since it went public in 2004, but was the second in a row following a fourth-quarter ad sales drop of 3.6%.

Excluding items, Alphabet reported earnings per share of $1.17, beating an average estimate of $1.07 per share.

"Google exceeded both revenue and earnings per share expectations this quarter, but reasons for investor optimism are modest," said Insider Intelligence senior analyst Max Willens.

He said turning a profit in cloud computing was "notable" but "the reality is that Google Cloud remains comfortably behind its two most important competitors, and its growth is slowing." Sales for the unit rose to 28% to $7.41 billion.

As well, advertisers, who contribute the bulk of Alphabet's sales, have curtailed their spending in response to a shift by consumers back to in-store shopping in the wake of eased masking and other restrictions. Marketers are experimenting more with new platforms like TikTok, which attracts a more youthful audience.

The company, meanwhile, has been looking to keep a tight control on costs amid recession fears and in January decided to cut about 12,000 jobs. Chief Financial Officer Ruth Porat told investors on a conference call that she expected capital expenditures this year to be "modestly higher" than in 2022.

Alphabet has otherwise sought to pare spending, including on employee perks and use of company resources. Porat told workers in an internal email in March that they should anticipate additional cost-cutting measures in the coming months.

She said on Tuesday's call that Alphabet endeavors to "durably engineer our cost base" in order to invest in priorities like cloud computing and artificial intelligence.

Alphabet’s Google unit has been scrambling to keep pace with rivals, notably Microsoft Corp, in rolling out new artificial-intelligence software that can generate long-form responses to queries and other prompts. Microsoft committed $10 billion to OpenAI whose ChatGPT software has been the talk of Silicon Valley since a free version was introduced in November.

Microsoft on Tuesday also beat Wall Street estimates for third-quarter profit and revenue, driven by growth in its cloud computing and Office productivity software businesses, pushing its shares up 8.5% in after-market trading. Shares of rival tech companies Meta Platforms Inc and Amazon.com Inc were up 2.3% and 5.3%, respectively.

Alphabet's revenue for the quarter ended March 31 stood at $69.79 billion compared with estimates of $68.95 billion, according to Refinitiv data.

It reported net profit of $15.05 billion for the first three months of the year compared with $16.44 billion a year earlier.

(Reporting by Akash Sriram in Bengaluru and Greg Bensinger in San Francisco; Editing by Arun Koyyur, Sayantani Ghosh and Matthew Lewis)