Google has agreed to acquire cybersecurity company Mandiant Inc. for $5.4 billion, its second-biggest deal ever.

With Mandiant, Alphabet Inc.’s Google gets more tools to protect its cloud clients by responding quickly to online threats. The company is working to recruit and support cloud customers amid stiff competition from Microsoft Corp. and Amazon.com Inc.

Google will purchase Mandiant for $23 a share in an all-cash deal, according to a statement on. Following the close of the deal, Mandiant will be part of Google’s cloud business.

Microsoft was also interested in Mandiant, but pulled out of talks more than a week ago, said two people with knowledge of the deliberations who asked not to be identified because the situation is private. Microsoft ended its takeover discussions on concerns that Mandiant’s collection of security businesses wasn’t a good enough strategic fit, according to one of the people.

The cloud business could help Google diversify beyond advertising, which comprises the bulk of its revenue and profit. Under Chief Executive Officer Thomas Kurian, who took over in 2019, Google Cloud has sought myriad ways to expand, working to make the service more reliable and revamping its partnerships to engineer bespoke projects for more clients.

The cloud division’s sales grew 47% in 2021, but competitors maintained stubborn leads. As of the fourth quarter of 2021, Google held 10% of the cloud provider market, while Amazon commanded 33% and Microsoft has captured 21%, according to data from Synergy Research Group.

Mandiant was founded almost two decades ago by Kevin Mandia, a former U.S. Air Force officer, and has gained a reputation for its incident response services. Its discussions with Google, first reported by the Information website, sent shares of Mandiant up 16% at the close of trading Monday.

The stock gave up some of those gains in late trading after Bloomberg reported that Microsoft had pulled out of talks, a sign investors were anticipating a bidding war. The shares slipped as much as 6.1%.

Mandiant became a stand-alone company again last year when FireEye Inc. sold its security-product business for $1.2 billion to a consortium led by Symphony Technology Group. FireEye had acquired Mandiant in 2013. Following Monday’s rally, the takeover target has a market valuation of $5.26 billion.

The deal will dwarf every previous Google transaction — other than its 2012 acquisition of Motorola Mobility for about $12.5 billion.

For Google, the biggest challenge may still lie ahead — getting regulators to sign off on the deal during numerous antitrust investigations. It took more than 14 months before Google could close its $2.1 billion purchase of tech wearable company Fitbit, due to regulatory scrutiny, and Google may be in for more of the same with Mandiant. Meanwhile, rival Microsoft has been on an acquisition tear, snapping up Activision Blizzard, Nuance Communications and 14 other businesses in the last year, according to its website.