(Reuters) - Intel Corp <INTC.O> said it would spin out its cyber security division, formerly known as McAfee, and sell a majority stake in it to investment firm TPG for $3.1 billion in cash.

TPG will own 51 percent of the new entity, valuing the entire company at $4.2 billion including debt.

Intel, which bought McAfee for $7.7 billion in 2011, will retain a 49 percent stake in the business.

The deal ends a failed effort by Intel to stake out a major position in the computer security business. At the time of the acquisition, Intel spoke of integrating McAfee security technology into its chips, but little came of those plans.

Intel executives at the time also said they hoped the acquisition would give it a piece of the emerging business of protecting corporations from sophisticated espionage, but newer players such as Mandiant, now a unit of FireEye <FEYE.O>, came to dominate that business.

At the same time, PC growth slowed, eroding the traditional McAfee customer base’s potential.

The unit, rebranded as Intel Security Group in 2014, will revert to the McAfee brand name following the closing of the deal, expected in the second quarter of 2017.

McAfee’s founder, John McAfee, was for a time on the run from a murder investigation in Belize and is a pariah in the industry. He recently sued Intel to get back the right to use his name.

Chris Young, Intel Security's general manager, will be named chief executive of the new company.

Intel Security's revenue rose 11 percent to $1.1 billion through the first half of this year, the company said in a statement.

TPG, which is making a $1.1 billion equity investment in the company, first approached Intel’s board about a potential transaction for McAfee around a year ago, sources familiar with the matter said.

TPG also led a $120 million investment round for security startup Tanium last year and was the lead investor in a $100 million funding round in internet security firm Zscaler.

(Reporting by Supantha Mukherjee in Bengaluru, Joseph Menn in San Francisco and Liana Baker in New York.; Editing by Jonathan Weber and Alan Crosby)