Intel's Brian Krzanich was forced out as CEO following an investigation into a "consensual relationship with an Intel employee," the company announced Thursday.

Krzanich has also left the board, it said.

Chief financial officer Robert Swan will step in as interim CEO, effective immediately, and the board has already begun the search for a permanent replacement.

"An ongoing investigation by internal and external counsel has confirmed a violation of Intel's non-fraternization policy, which applies to all managers," the company said in a statement. "Given the expectation that all employees will respect Intel's values and adhere to the company's code of conduct, the Board has accepted Mr. Krzanich's resignation."

Krzanich violated a policy that said managers cannot have relationships with people who report to them either directly or indirectly. The relationship ended and took place "some time back," people familiar with the situation told CNBC. It's unclear with whom Krzanich, 58, had the relationship.

The company was only recently made aware of the relationship, at which point it began probing and Krzanich was asked to resign, the people said.

Krzanich's total compensation topped $21 million last year, and the company paid for his transportation and residential security, according to company filings.