The novelist EM Forster stopped writing in his forties because having gay sex killed his creative drive, a scholar claims.

The author of works such as A Room With A View and Howards End stopped writing in 1924, after he published A Passage To India. He lived until 1970.

His abrupt halt in productivity has been seen as one of the great British literary mysteries but a scholar claims to have discovered why.

According to Wendy Moffat, associate professor of English at Dickinson College, Pennsylvania, Forster had sex with a man for the first time at the age of 38.

Afterwards, she said, he felt he could no longer convincingly write about the lives of middleclass straight people, as the majority of his books had been about.

Only one novel, Maurice, dealt with gay issues. It was written in the 1910s but was not published until after Forster’s death.

Prof Moffat has gained access to Forster’s deeply personal unpublished papers, which were previously locked away at his former home at Cambridge University.

In one diary entry, he wrote “I should have been a more famous writer if I had written or rather published more, but sex prevented the latter.”

Prof Moffat told the Sunday Times: “He never had sex until he was 38, although he never had any doubts – even from a very young age – that he was gay.

“The marriage plot fiction had become a masquerade to him – yet he could not bring himself to publish Maurice, which would have outed him.”

Forster lost his virginity aged 38 to an injured soldier on an Egyptian beach. He met his long-term lover – a married policeman – some years later.

His only gay novel, Maurice, was about two young men at Cambridge and a gamekeeper and focused on isolation in a heterosexual society.

It was not published until 1971, 18 months after his death. Forster apparently thought publishing it would be too controversial while homosexuality was illegal.

One poignant entry in his diaries said: “Now I am 85 how annoyed I am with society for wasting my time by making homosexuality criminal. The subterfuges and the self-consciousnesses that might have been avoided.”