IBM says it has agreed to acquire US software company Red Hat for $34bn, as it seeks to diversify its technology hardware and consulting business into higher-margin products and services.

The transaction is by far IBM’s biggest acquisition. It underscores chief executive Ginni Rometty’s efforts to expand the company’s subscription-based software offerings, as it faces slowing software sales and waning demand for mainframe servers.

“The acquisition of Red Hat is a game-changer; IBM will become the world’s No. 1 hybrid cloud provider, offering companies the only open cloud solution that will unlock the full value of the cloud for their businesses,” said Rometty in a statement.

It is also the third-biggest acquisition in the history of the US tech sector, after the $67bn merger between Dell and EMC in 2016 and JDS Uniphase’s $41bn acquisition of optical-component supplier SDL in 2000, just as the dot-com bubble was bursting.

Founded in 1993, Red Hat specialises in Linux operating systems, the most popular type of open-source software, which was developed as an alternative to proprietary software made by Microsoft. Headquartered in Raleigh, North Carolina, Red Hat charges fees to its corporate customers for custom features, maintenance and technical support, offering IBM a lucrative source of subscription revenue.

IBM is hoping the deal will help it catch up with Amazon, Alphabet, and Microsoft in the rapidly growing cloud business. IBM shares have lost almost a third of their value in the last five years, while Red Hat shares are up 170% over the same period.

Other big technology companies have also recently sought to reinvent themselves through acquisitions. This year, Microsoft acquired open source software platform Github for $7.5bn, chip maker Broadcom agreed to acquire software maker CA Inc for nearly $19bn, and Adobe agreed to acquire marketing software maker Marketo for $5bn.

One of IBM’s main competitors, Dell, made a big bet on software and cloud computing two years ago, when it acquired data storage company EMC for $67bn. As part of that deal, Dell inherited an 82% stake in virtualisation software company VMware.

The deal between IBM and Red Hat is expected to close in the second half of 2019. IBM said Red Hat will continue to be led its chief economist Jim Whitehurst and Red Hat’s current management team. It intends to maintain Red Hat’s headquarters, facilities, brands and practices.