Dr. Dre and Jimmy Iovine are the central characters in HBO’s “The Defiant Ones.” (Joe Pugliese/HBO)

Director Allen Hughes’s dazzling and definitive four-part HBO documentary “The Defiant Ones,” which chronicles the unlikely pairing and mutual rise of record producers Dr. Dre and Jimmy Iovine, sets out to tell a rags-to-riches story, but it mostly dwells on the riches.

The film, more than four hours long end to end, is the kind of solid but friendly documentary all celebrities dream of having made about them, awash in jaw-dropping sweeps of Malibu beach houses, visits to luxe mansion interiors and private-jet cabins, supplemented by drone’s-eye views of yachts and estates and perfect lighting everywhere Iovine and Dre go. Despite its fixation on provocative and at times harrowing (and even criminal) travails, “The Defiant Ones” never stops basking in the permaglow of their success, which, seen here, is more beautiful than any high-definition film about marine life. Even Tom Petty looks gorgeous.

With the determined thoroughness of a rollicking 700-page biography, “The Defiant Ones” devotes its first two (and most interesting) episodes to exploring the wildly different early lives of Iovine, 64, the son of a Brooklyn longshoreman, and Dre (Andre Young), 52, born to a single mother in Compton, Calif.

A shiftless Iovine, who hated Catholic school and loved rock-and-roll, got a job mopping floors and answering phones at recording studios, eventually working as an engineer, lucky enough to be the only techie available for sessions with John Lennon and, most memorably, seeing Bruce Springsteen through the arduous making of “Born to Run,” the singer’s breakout album. From there, Iovine finds his true talent for dealmaking and hit-spotting, working with Patti Smith, Stevie Nicks, Petty, U2 and other chart-toppers. Though he possesses natural talents for both audio engineering and album producing, Iovine’s true knack is a form of alchemy, an ability to mix talented people and encourage and then extract their best work, exploiting it to superstardom.

“[Iovine] happens to you,” says U2 frontman Bono. “He’s like a virus that enters the system uninvited. . . . He knows this is going to work out well for both of you.”

Dre’s story is more fascinating, incorporating as it must the emergence of a subgenre — gangsta rap — within the larger creation story of rap and hip-hop in the 1980s. Dre also comes across as a far more complicated man than Iovine. Despite all the hours (years, in fact) of access he has given to Hughes, Dre’s innermost thoughts remain enigmatic and obscured, even if his shortcomings are more prominently displayed. (Including the time he assaulted a female TV host, among other skirmishes with the law that led to a brief 1994 prison sentence.)

What’s most clear, when comparing Dre and Iovine, is that Dre has the superior ear and technical know-how. His earliest production work, made at home, “just sounded better than anything on my speakers,” Iovine says.

By the early 1990s, Iovine was running his own record label, Interscope, which came to the rescue of Dre’s label, Death Row Records, during a particularly fiery period in America’s culture/media wars, as critics sought to blame Dre, who first found notoriety with his group N.W.A. and the controversial rap song “F--- tha Police,” and his cohort (Snoop Doggy Dogg, Tupac Shakur) for a rise in crime and the overall decline of civilization.

“The Defiant Ones” treats the height of gangsta rap (including the rivalries between East and West Coast rappers and the 1996 shooting death of Shakur) in much the same way that Ken Burns treated the history of jazz, but without as much context as Ezra Edelman’s “O.J.: Made in America.” At this point in the story, it might have been wise to slow down and probe a little more than Hughes does.

Interscope, with artists like Nine Inch Nails and Marilyn Manson, was familiar with the art of provocation and the blowback from would-be censors, but more than that, Iovine desperately admired the music that Dre and others were making — enough to defy executives at Time Warner, then the labels’ parent company, and keep putting out the edgiest material possible. Supporting Dre ensured the discovery and signing of upcoming talent, including Eminem, 50 Cent and Kendrick Lamar.

The 21st century arrives like a morning-after headache, and the record industry begins to reel from the arrival of Napster and other music-sharing websites that eviscerate the business model. It’s here that “The Defiant Ones” begins to fall back on platitudes and executive-suite back-patting, telling the story of Iovine and Dre’s necessary pivots as moguls in a digital era — ending, most spectacularly, with the creation of Beats Electronics, an idea for stylish, top-notch headphones that they ride to a $3 billion deal with Apple.

By the end of Part 4, the documentary has dwelled too much and too long on their self-satisfaction (particularly Iovine’s), which is fine if you like watching rich people enjoy the twilight.

Where “The Defiant Ones” really soars however — and where it can teach all of us a lesson — is by capturing what happens when we open our minds and ears to one another. There is no logical reason Iovine and Dre belong together in the pantheon of media moguls, except that they heard and understood each other on a level that transcended race, background and personality. It’s one of the great bromances of our time.

The Defiant Ones (four parts) begins Sunday at 9 p.m. on HBO. Continues nightly through Wednesday, July 12.