One day in 1973, Sofia Gubaidulina was attacked in the lift of her Moscow apartment building. The man started to strangle her. The composer thought grimly that this was the end and, if so, her chief regret was that she would never complete the bassoon concerto on which she'd been working. "I'm not afraid of death but of violence," she told her biographer later. She got exasperated with her attacker. "Why so slow?" she asked. Amazingly, the words scared him off.

Who was he? "Friends have said it must have been a KGB agent, but it could have just been a crazy person," she says, over black tea and biscuits at the house in Appen, a village north of Hamburg, where she now lives. Perhaps: but more likely her friends were right – the KGB had already turned over her apartment searching for dissident writers' microfilms and samizdats.

In any case, Gubaidulina was often trouble to the Soviet authorities. She consorted with dissidents(notably her second husband Nikolai Bokov, dared to attend unauthorised western music festivals, wrote music that expressed religious convictions and was ultimately blacklisted at the Sixth Congress of the Composers of the Union of Soviet Socialist Republics – denounced, along with six other composers, for producing "noisy mud instead of real musical innovation". She thus became one of the Khrennikov Seven, most of whom then went into exile – including her close friend Viktor Suslin, with whom she had played in an improv folk ensemble.

But not Gubaidulina. "Being blacklisted and so unperformed gave me artistic freedom, even if I couldn't earn much money," she says. "I could write what I wanted without compromise."

On the mantelpiece behind the 82-year-old composer is the Golden Lion she won at the Venice festival earlier this summer. Half a lifetime after that attempted strangling, Venice honoured her for a musical career "permeated by a spirituality that is both delicate and incandescent, and that has brought her fame and admiration around the world". She completed not just the bassoon concerto, but went on to write many other extraordinary works, a handful of which can be heard at London's Southbank Centre this weekend.

Two in particular give a sense of her oeuvre, notably Offertorium (the violin concerto she wrote for compatriot Gidon Kremer) and her third string quartet, which includes two prerecorded tapes: one with instruments tuned a quarter tone higher than the live instruments and the other an extended ricochet produced by a ball bouncing across the strings.

Over tea, Gubaidulina had been trying to explain the differences between what she suffered during the Brezhnev years and what previous generations of composers endured. "Shostakovich withdrew works rather than face jail under Stalin," she recalls. "He had to compromise, and write music in response to what he was obliged to call 'just criticism'." Andrei Zhdanov, the Soviet politician whose doctrine was known as zhdanovshchina, notoriously attempted to define permissible revolutionary art and labelled what he called "incorrect art" as counter-revolutionary. What would she have done in Shostakovich's shoes? "Withdrawn the music! Who wants to go to jail? I was freer than him or Prokofiev. They suffered so much from politics. We didn't. It wasn't life or death for us."

Really? But what about the stranglings and state denunciations? She looks up through her fringe as she sits hunched and thoughtful on the edge of her green leather sofa. "Artists almost never have easy lives."

Her life was steeled against such adversities when, in 1959, she met Shostakovich and played for him on the piano the symphony she had written for her final examination as a student of composition. He praised it and said: "My wish for you is that you should continue on your own incorrect path." That "incorrect" was resonant, certainly for anyone who'd suffered under zhdanovshchina: the greatest Soviet composer was encouraging the twentysomething student to go her own way.

"I am grateful the whole of my life for those wonderful words," she says. "They fortified me and were exactly what a young composer needed to hear from an older one. It gave me the courage to follow my own path."

That path is a complicated one that takes us through the thickets of 12-tone serialism, post-serial microtonal Russian music, outré folk music improvisations using Georgian hunting horns, mysticism and exile. But one bright thread led through this: she has always insisted that her music must aim at reuniting mankind with God.

Gubaidulina was born in poverty in the Tatarstan capital of Kazan in the early 1930s. The granddaughter of an imam whose father was a Soviet engineer, the five-year-old Sofia would dance entranced down the street as she followed one Shurka Durak (which translates as Shurka the Knucklehead), an itinerant accordionist. It was her first musical love: "I loved then, as now, the instrument's ability to breathe – no other orchestral instrument has this." You can hear the fruits of that obsession in mature works for classical accordion such as the sonata Et Exspecto, in which, apart from tremolandi, quiet chorale sounds and toccata moments, one hears the uncanny breathing of the instrument as the soloist squeezes the bellows.

It was the piano, however, that would become the musical centre of her life. Her parents bought an "awful" baby grand on which her sister Vera would play the keys while Sofia fiddled with the strings. Just like John Cage, I suggest. "Yes! You can really say that we were given riches by our very poverty," she says. "I wanted to become a composer from very early because I was convinced there was too little music in the world. We needed more." She smiles: "Maybe I was wrong in believing that."

Gubaidulina's development as a composer, which took her to conservatories in Kazan and Moscow, was crucially influenced by her relationship with her third husband, musicologist and conductor Pyotr Meshchaninov. He taught that the 12 tones were not enough: the octave could be divided into 72 units. He also suggested that music evolved through eras – that there was linear period, followed by harmonic and sonoristic periods. "I realised that as a composer of a sonoristic age I must focus on rhythm, and that was what led me to increasingly use the Fibonacci system in dividing up rhythm and time in my music. The Fibonacci system is always about approaching the divine."

No doubt, I suggest, all this divine numerology exasperated Soviet socialist realists. But is it fair to characterise the spiritual nature of her music simply as a counterblast to the atheism and materialism of Soviet society? That, after all, is how her work is characterised in the programme notes for The Rest Is Noise festival's Politics and Spirituality chapter, where her music is programmed with works by fellow eastern European Christians, including the Estonian Arvo Pärt andthe Pole Henryk Górecki.

But wouldn't her music have been equally spiritual even if she hadn't been born and raised in the anti-religious Soviet Union? "True art for me is always religious, it will always involve collaborating with God."

In this she is a true follower of Nikolai Berdyaev, the Russian philosopher exiled from his homeland by Bolsheviks in 1922. Berdyaev proposed that creative humans continue the process that God initiated in creating the world from the void. God, as it were, needs us to continue his work. And yet every creative act involves a "traitorous compromise with time" since inspiration is always mangled in realisation. "It is this compromise," wrote Berdyaev in The Meaning of the Creative Act, "That fills the whole realm of culture with a great sadness and leaves an insurmountable bitterness at the heart of every creative being."

"All this means a great deal to me," says Gubaidulina. "That is the sadness at the heart of my music." Perhaps that sadness is just a Russian thing: at the Huddersfield Contemporary Music festival in 1986 she said: "Russian music is always about pain." Or perhaps it's not just Russian. Indeed, she says she found a kindred spirit in TS Eliot when she read the Four Quartets. "His thinking about time – that past, present and future contain each other – very much struck my mystical thoughts about eternity." It led her to write Hommage à TS Eliot (1987) for octet and soprano in which she set some of Eliot's verses.

More pertinently, though, she felt a close affinity with Eliot for what he wrote in Four Quartets, that every attempt to create verse "is a wholly new start, and a different kind of failure". "My music is like that," she says. "All my work is just attempts. I know that when I write that it will never fulfil my intuitive hopes for it – that is why it is sad."

One of the intriguing things about Gubaidulina is that, for all she suffered under the Soviet system, it was only after it collapsed that she left her homeland. "It was hard to live – there were shortages and life was easier in Germany. I have never considered myself an exile – I go back to Russia a lot." Then why not live there? "Until I came here I always lived in cities but that is increasingly impossible. I need silence to write. Here I have the woods around me, in which I can walk without interruption. I live in a village with only two roads." She chuckles. "It turns out that's not remote enough: Günter Grass says he lives in a village with only one road."

She has been creatively fruitful in Appen, not least writing Sonnengesang (1997) for the great exiled Russian cellist Mstislav Rostropovich, and her St John Passion (2000), a homage to her beloved JS Bach. But the fecundity came to an abrupt halt last year. "It was a crisis year. I thought I would never write again." No wonder perhaps: her third husband and her daughter died, and, that summer, her friend Viktor Suslin, who had settled in this same village years previously. Today she lives a solitary life – except for Suslin's widow, a few doors down, and musical admirers from around the world.

Earlier this year, though, she returned to writing, composing a chamber piece called So Sei Es (So Be It), dedicated to Suslin. The title becomes the refrain of the last few minutes of our meeting. Will you write more? "I am old, and it is harder to write than ever."

It's nearly dusk as I kiss Sofia Gubaidulina goodbye. "But so be it," she says. "Whatever I write is just an attempt. For us human beings nothing is ever realised as we imagine. What we do is just attempts. That's our lot. So be it."

• Sofia Gubaidulina is talking at The Rest Is Noise festival on 2 November. Details: therestisnoise.southbankcentre.co.uk