Gayle King confronted 50 Cent at a black-tie gala about his history of “talkin’ s–t” about her best friend, Oprah Winfrey, we’ve exclusively learned. The showdown led to a rapprochement between Winfrey and the rapper — before he eventually turned on King.

In his forthcoming book, “Hustle Harder, Hustle Smarter” — seen by Page Six — Fiddy says that he bumped into King at a fête for Bette Midler’s foundation. “Gayle is the real deal — a very sophisticated, secure, and smart lady. She’s never afraid of a situation … so she marched right up to me and basically said, ‘Why you talkin’ s–t about my girl?’” he recalls.

Fiddy had publicly dissed talk-show legend Oprah with barbs such as, “Oprah’s audience is my audience’s parents, so I could care less about Oprah or her show.” He even named his dog Oprah.

Fiddy told King he assumed Winfrey didn’t like him because he’d heard her criticize his brand of hip-hop as violent and misogynistic — and he figured he may as well get some press for taking digs at her publicly. He writes that he often uses faux beefs with celebs as a “strategy” to make people talk about him. “Listen, I’d love to be Oprah’s friend,” he said he told King. “But if we can’t be friends, could we at least be enemies?”

In the tome, out April 28 from Amistad Press, Fiddy says King arranged for him to appear on Winfrey’s “Oprah’s Next Chapter” in 2012, and they buried the hatchet. “Before meeting me, they had bought into the 50 Cent persona … Someone who got into beefs and drama because he just couldn’t help himself,” he writes. “But when I said, ‘At least let me be an enemy,’ they understood that when I got into a beef, it was never driven by emotion. Instead, I was moving off of strategy.”

But tensions flared among the group again this year when 50 Cent trashed King for a “CBS This Morning” piece she did on Kobe Bryant. Fiddy and Snoop Dogg claimed it unfairly dredged up Bryant’s sexual-assault case after his death.