March 1989, I open a large record envelope and a waft of patchouli oil hits my nostrils. Inside is the new Madonna album. The cover art features hippy beads and her crotch in jeans. This image is a nod to her mother, a devout Catholic of French-Canadian stock, who covered up their Sacred Heart statue when a woman came round the house wearing zip-up jeans. “In Catholicism you are born a sinner … the sin is within you the whole time,” Madonna said at the time. Dedicated to the memory of her mother, Like a Prayer explores the impact of her Catholic girlhood, disappointment in love and transformation of self. Compared to the sugar-sweet True Blue, this is a startling reinvention.

During recording, from September 1988 to January 1989 at Johnny Yuma studios in LA, Madonna was at the worst point in her marriage to Sean Penn. She had filed for divorce the previous year but was spending time with him trying to work things out. “I remember some days she wore sunglasses all day in the studio,” recalls her then co-songwriter and co-producer Patrick Leonard. “She was going through very hard times.” Making the record, however, was her salvation. After the bouncy grooves of 1984’s Like a Virgin and the upbeat celebration of her love for Penn in True Blue (1986), Madonna was in a more introspective mood. Penn had an explosive temper, and as their marriage foundered amid constant fighting, her career hit a stale patch with professional flops Shanghai Surprise, the film she starred in with Penn, and Who’s That Girl, a comedy heist movie with a patchy soundtrack. Madonna found a focus for her divorce madness in the new album.

“We knew she was going through a lot of personal stuff,” recalls Donna De Lory, who, along with Niki Haris, sang backing vocals. “We were friends, and I knew that she was channelling all that emotion into the music. It was going to be a much more personal record for her.” Madonna had just turned 30 and approached the studio like a confessional. “She was writing songs that were very truthful,” says her other co-songwriter and co-producer, Stephen Bray. “She has an interesting relationship with fear in that she compartmentalises it and then it comes out in her ferocity of personality. True Blue was about feeling romantic and wanting to be unabashed about love. Then she changed chapters. ‘Things didn’t work out the way I thought.’ That’s how Madonna processes fear, in Freudian pop writing – free association turned into pop songs.”

In the 1980s Bray and Leonard were Madonna’s main creative collaborators. Michigan natives like her, they had strong ideas and worked hard, which she respected. Leonard pushed Madonna to create songs that were intensely emotional experiences. “We were like yin and yang, polar opposites, and that can bring out your best, most committed work,” he says. “We built a chemistry.” They first met when he was her musical arranger on the Like a Virgin tour, and she chose him to produce True Blue and Like a Prayer. “We argued a lot during the recording sessions,” he recalls. “But one day she held up the True Blue album cover and said: ‘Whose picture is that?’ The more feisty conversations stopped there!”

The title track marks a pivotal point in Madonna’s career. In dismantling old Catholic patriarchal messages she created a concept album, moving from pop stardom to artistry. The video – which depicts Madonna kissing a black saint and dancing in a field of burning crosses – fuses the sacred and the profane in a boldly provocative way. “I came in with the music, the gospel influence, and Madonna added the words,” says Leonard. “The protest against the church came later in the video. But it’s a testament to the weight of the song that this vessel could hold it. When we wrote it, it felt like being on fire.” “It’s a song that explores the word ‘prayer’,” says Andraé Crouch, leader of the Los Angeles Church of God choir singing on the track. “Madonna wanted something very churchy, so I tried to blow up what she did and make it as powerful as I could.” Madonna encouraged everyone in the studio to surrender themselves to passionate abandon. “It was an out-of-body experience,” says bassist Guy Pratt, whose improvisatory solo is a high point of the track. “As I was playing Madonna was going: ‘Guy, more! More!’ By the fade I had run out of licks and had to go back to the beginning again. It’s amazing having that bassline on that song.”

Madonna moves from the declamatory Like a Prayer to the quiet, tender ballad Promise to Try, where she addresses her mother and the impact of her death. Leonard recalls: “I played the piano and she sang. She was right at my shoulder, next to the piano, with no headphones. The record button got pushed twice.” Much of the album was recorded as live, and Leonard says this is why it still resonates now: “The songs were built around chord progressions and melody, and it was a more personal process, not the product of big songwriting teams. What listeners are responding to is the energy of the performances in the room.” Oh Father, for instance, an emo-style ballad about her troubled relationship with her dad, was recorded with top-flight musicians including drummer Sugarfoot Moffett and brass arranger Chuck Findley. “I had nine people in the room,” remembers Leonard. “Madonna said: ‘Why all these people, does it make a difference? Do we have to do this?’ I said: ‘It’s not going to be painful, it’ll be fun.’” He admits now that the sessions weren’t always fun. “I had managers checking in, and the record company checking in, asking to hear stuff. I was sitting in the hot seat having to sell it to everybody.”

Madonna in 1989. Photograph: Araldo Di Crollalanza/Rex

He knew they were creating something unique from their own “strange little aesthetic”. Rolling Stone magazine came into the studio one day, asking which radio stations Leonard and Madonna listened to. “We don’t listen to any,” they both said. “Really? How do you know what’s going on?” “We decide what’s going on,” said Madonna. Recording the track Love Song with Prince scored hip cred points but, ironically, the whimsical assemblage of guitar parts and overdubs is one of the album’s weaker moments. Bray says he was asked to work on the track but felt overawed. “I am the biggest Prince fan, but to be honest I was too shaken. This was before I discovered beta blockers – I wasn’t emotionally ready,” he says. “It’s one of my few regrets in life that I said: ‘Nah, you guys don’t need my help.’ I’d have made it prettier and brought some lushness to it.” Bray was excited to work with Prince’s guitar sounds on the funky Sly Stone homage Keep It Together. Although upbeat, there was real tension in this exploration of sibling rivalry. “Madonna was getting out some of the complications about family and her success,” recalls Bray.

The album’s darker tracks are balanced by moments of childlike innocence, such as Cherish. It features Madonna, Haris and De Lory singing together with ebullient energy. “We worked on it until we were really tight,” says De Lory. “Madonna knew exactly what she wanted and how to break it down.” Haris remembers that they made a good team on the Who’s That Girl tour, and brought that vibe into the studio: “We tried to enrich rather than embellish her sound.” For De Lory, the Like a Prayer sessions were personally inspiring. “Madonna was like the big strong sister who doesn’t put up with stuff from the guys. As a producer she lay down boundaries. I loved seeing that – it gave me an example of how I could be strong too.”

That strength is most evident on the Stephen Bray-produced track Express Yourself, which has since become a feminist anthem. “We didn’t invent feminism, but this was a call to action,” says Bray. “Madonna is an incredible example of a woman saying: ‘I’m doing this my way.’” He compares her to Daenerys in Game of Thrones, emerging from the fire. “This was an extremely cathartic song for her. In love you get burned, but it doesn’t destroy you. I’ve become even more proud of the song in recent years. What’s horrifying about A Handmaid’s Tale is how frighteningly current that feels. That’s not a dystopian fiction, it’s happening politically. To have co-written a song about telling one’s truth and demanding to be treated as an equal and as a partner – I couldn’t be more proud.”

Lucy O’Brien’s Madonna: Like an Icon is out now; Patrick Leonard’s Bring the Circus Home will be released soon; Donna De Lory’s Here in Heaven is out now