On a recent trip back to Havana, where I lived for three years, my Spanish teacher told me she thought Cuban music had saved my life. We had been talking, as usual, about the passion that had gripped me in recent years. I had previously dismissed salsa dancing as a marker of a midlife crisis and yet here I was, doing it into the small hours, becoming that cliche. But I had given little thought to the changes that had taken place along the way.

I moved to Havana at the end of 2011 for my wife’s work and I was increasingly beset by feelings of failure. A few years earlier, I had entered my 40s and thought that I had finally found my purpose through writing. With my first book behind me, I began work on a memoir of youth. But rather than release me from the grip of the past, it enmeshed me further in negativity and self-criticism. Nothing I wrote pleased me, probably because the subject was myself. Cuba’s sun, rum and palm trees were no medicine. My wife thinks I was in the grip of depression. Reluctantly I have come to accept that she is probably right.

Not having children – which perhaps compounded the sense of meaninglessness – left me with time to wander suburban Havana streets. Beneath the blazing sun, I fretted a lot about writing and produced very little. As I walked, I would sometimes be drawn by the music from neighbourhood parties. Peering through cactus hedges, I would see people dancing in their yards, perhaps a grandfather teaching a child. The scenes were touching, yet made me sad.

I like to think that what I saw on those aimless, sweat-soaked walks sowed the seeds of my future passion. But I might well have continued to live a danceless life had my wife not started salsa classes. Two years into our time in Cuba I decided to join her, thinking that if I didn’t dance in Havana, I never would.

I headed for that first class like I was going for root canal treatment. The only kind of dancing I had done before was the pogo. In my younger years, I would be the one glowering on the edge of dancefloors gripping a pint. Now a 6ft 3in grey-haired Yorkshireman, I was not well set up for salsa. My early steps were big and cumbersome. “Dance as if nobody is watching” is the standard advice to beginners: I danced as if the whole world was not only watching, but judging and laughing.

Thankfully, all of that is behind me. Improvement came slowly, not just through classes but through many hours of dancing with all kinds of people and countless live concerts where the music began to flood my tired soul. It came from watching Cubans dance – less the flashy young ones who make a living from it, more the ordinary social dancers in faded venues off the tourist track. I studied the elderly veterans who had actually created the dance around the time of Castro’s revolution. It felt magical sharing the floor where it all began, participating in a great tradition.

To change is tough, and for me self-doubt and depression are always lurking. People try to mend themselves in different ways, but the introspection of my memoir project had burned me out. It had been a brutal form of self-therapy, with no professional for protection. Still, I never expected that dance, rather than words, would be my cure. It has helped me out of my isolation, and my own head, connecting me with worlds far from my own.

Knowing my way around a dancefloor and leading – in Cuban salsa the man is in that role – has given me back some sense of confidence, if only for a few, fleeting minutes at a time. Dancing to live music in Havana has also brought me joy, elation even, of the kind I haven’t felt through music since my teenage years. Though I live far away now, I return when I can to recapture that mood.

My Spanish teacher is probably right: Cuban music did save me. On Havana’s rutted dance floors, I learned to move through the world in a different way.