Sharon Osbourne exacted the ultimate revenge when rocker hubby Ozzy fell off the wagon — she sold all his cars.

In her forthcoming memoir “Unbreakable,” excerpted in the Sun newspaper, she explains Ozzy went wild earlier this year at their Buckinghamshire, UK, home while Sharon was in Los Angeles working. Aides said “it was like having the Exorcist in the house.”

Over the phone, Ozzy told her, “I think I need to be a bachelor.”

Later, Ozzy, 64, sped off to a pub in an Audi R8. Aides found a note under the wiper from a dealer offering the Black Sabbath rocker drugs, while Ozzy was drunk inside. He returned the next morning with a bottle of vodka and crate of beer.

Furious, Sharon arranged to get rid of Ozzy’s $800,000 car collection. She sold the Audi and one Ferrari he kept in the US. The other Ferrari she gave to their son, Jack.

In the book, Sharon, 60, writes the couple, married since 1982, nearly divorced because of his antics. Ozzy eventually apologized and agreed to go to Alcoholics Anonymous.

“It’s the most expensive drink I ever had,” Ozzy said.