For the last few years, the writer, actor and comedian Matt Berry has quietly got on with making a series of albums that, in his own words, “have been heartfelt”. Now, after Witchazel (2011), Music For Insomniacs (2014) and Kill The Wolf (2013) comes The Small Hours. This time, he has made his masterpiece.

The Small Hours is inspired by those late night and early morning moments when thoughts are amplified, minor concerns become insurmountable, and an overwhelming sense of dread accompanies lying awake and staring up at the ceiling, praying hopelessly for sleep. Religious confusion, self-doubt, heartbreak and loneliness are also touched on in an album that demonstrates how we all suffer from fear and uncertainty, whatever our outward image might suggest to the contrary.

“This is the most personal and exposing album I’ve made,” says Berry.

“I listened to the voices deep inside my head. They called me weak, a loser and a coward,” sings Berry on Gone For Good. “It’s the edge of the dawn when I feel low, it’s the grey light that pours through the window,” he sings, with exquisite gloom, on the crepuscular title track. You probably know Berry as the self important actor Steven Toast of Toast Of London, the avuncular ladies man Douglas Reynholm of The IT Crowd, and the lip synch-challenged Dr Lucien Sanchez of Channel 4’s cult parody of a 1980s hospital drama, Garth Marenghi’s Darkplace. You probably don’t know the side of Berry revealed on The Small Hours. This is not the performer, but the man.

“I can see why people might listen to this and think: ‘dry your eyes mate, what have you got to complain about?’” says Berry. “I know how lucky I am and I don’t take any of it for granted, but there’s another side to what I do for a living, which is the insecurity it creates. It sounds pathetic but I hadn’t really thought about these things before, perhaps because I was on this trajectory where it was all me, me, me. Then I hit forty and suddenly I started thinking about death, religion, who we are.”

Those thoughts were the inspiration for Lord Above, a fast-paced, gospel-tinged song with a glorious trumpet solo but in a broader sense they run throughout The Small Hours. They inform the beautiful Seasons On Fire, even though it’s really about heartbreak, and cast a shade over Say It Again, a pretty evocation of loneliness.

“This album was written over the last three years, always during those moments of doubt and reflection, because that’s when inspiration tends to happen,” says Berry. “Nobody wants to hear a song called ‘Hey, I Just Won A Bafta.’”

After getting into acting as a way of, by his own admission, not having to get a real job, Berry discovered how the profession plays strange games on your sense of self. “I never, ever had the goal of being famous, but different concerns creep up on you the more your profile rises and if you’re not careful all the peripheral shit becomes important,” he explains. “That’s when I go back to something Bob Mortimer told me years ago. When you first get involved in this world you think there’s a special party where all the people who have made it go, some place that you’re not allowed into. Then you find there is no party. It’s a mirage. In the end, all that matters is the art. That’s what you have to focus on.”

The music of The Small Hours stretches way beyond the folk-rock of Witchazel and Kill The Wolf, beyond the Jean Michel Jarre-like electronics of Music For Insomniacs, into a rich and sophisticated blend of jazz, rock and movie soundtrack-style impressionism. “As much as possible, we played it live,” says Berry, who made the album with his touring band The Maypoles and his long-term collaborator, the singer and clarinettist Cecilia Fage. “With earlier albums I played everything myself but this time I did it the old fashioned way of making demos, taking them to the band, rehearsing for two days and then recording, on two-inch tape, at Rimshot Studios in Kent. Before adding all the fancy bits himself at his home studio. The key influence on the production was Fleetwood Mac’s Rumours, and you can’t get that quality of sound unless you go into a studio and record live. I’m not sure why the album headed in a jazz direction, except that we’re all Frank Zappa fans and we had the goal of making complex music that appeals to kids, which is what Zappa did.”

You can hear the result of that goal on Night Terrors, the remarkable ten-minute, flute- and organ-laden instrumental that sounds like the lost score to an avant-garde spy movie, but also on The Peach And The Melon, a fun 60s-tinged song about, of all things, the Manson family.

“The only reason Charles Manson sent his girls out to kill people was because they were getting bored,” says Berry. “They were missing home comforts like ice cream and telly, banality was creeping in, and he saw he was in danger of losing his grip. That’s when you realise how much bullshit cults — and religions — are built on. I’ve been doing work with Amnesty and you can’t help but come to the conclusion that religion is dangerous. The bad far outweighs the good.”

All of this contributes to an album that sounds like a lost late 60s / early 70s jazz rock classic while at the same time belonging entirely to the modern age. “I’m paid to aid escape, but where the hell am I to go to get away from it all?” Berry asks himself on Obsessed And So Obscure, articulating the plight of an entertainer who, knowing how much blood, sweat and tears must go into it, can no longer be entertained by his own art form. The answer is that he can escape into himself, into reflection, inspiration and deep musical expression. This wonderful album is the result of that journey.