Thirty years ago, on 9th January 1986, Michael Heseltine picked up his papers from the cabinet table, and walked out of Number 10, precipitating a political crisis for Prime Minister Margaret Thatcher.

The defence secretary had resigned.

On BBC One that evening, the Nine O'Clock News picked apart the political entrails.

At the same time, on BBC Two, in sitcom land, Britain was getting used to a new face in Downing Street, Jim Hacker. It was the first episode of Yes, Prime Minister.

Hacker's weekly battles with Cabinet Secretary, Sir Humphrey Appleby, were comedy, but talking to those who were in Whitehall and Westminster at the time, it sometimes seemed more like a fly-on-the -wall documentary.

Image caption Tony Blair tells me his sympathies were always with Jim Hacker

Back then, Richard Mottram was a young civil servant in charge of Mr Heseltine's office. Speaking to me for Hackers And Humphreys All, on BBC Radio 4 Extra, he underlined how life was not so far away from art.

"I said to him (Heseltine) 'have you told anyone?' because, being a good civil servant, I thought if he hasn't told anyone, we can always sort of 'un-resign' him. And he said 'Yes, I told the cameraman on the door', and then I realised we were doomed."

Jim Hacker began his screen life as a peripheral member of the cabinet in Yes, Minister (1980-1984), created and written by Sir Antony Jay and Jonathan Lynn.

The late Paul Eddington gave a memorable performance, bumbling from crisis to crisis, manipulated and checked by the late Nigel Hawthorne, who won successive BAFTAs for his verbal circumlocutions as Sir Humphrey.

Image caption The cabinet room set was closely based on the real thing

Perhaps the biggest challenge for Sir Antony Jay and Jonathan Lynn, the creators of the series, was making Hacker's elevation to Number 10 credible.

Lynn told me: "There have been a large number of barely competent prime ministers and Hacker joins that rogues' gallery".

Eddington, though, was thrilled.

"He looked more regal when I said to him I think you're going to be prime minister… he loved the idea," says Lynn.

Perhaps more important than the performances of the three main actors - Derek Fowlds as Bernard Woolley, Hacker's Principal Private Secretary, was the third member of the triumvirate who were in every episode of both programmes - was the quality of the writing.

Research was conducted over long lunches with politicians and officials. Most are unknown, but some are so proud of their association with the programme that they've outed themselves.

Image caption Margaret Thatcher wrote her own "Yes, Prime Minister" script

Antony Jay, a former TV current affairs producer, also had good contacts of his own, having written speeches for leading Conservative politicians, including Geoffrey Howe.

Margaret Thatcher was a great fan of the series. The programme filmed exteriors in Downing Street, Eddington was allowed to walk through the famous door as Prime Minister Hacker, and the production designer was even given a personal tour. The result was a near perfect reproduction on screen of the cabinet room.

In 1984, Mrs Thatcher offered a tribute of her own to Yes Minister.

Asked to present an award to the writers, with her Press Secretary Bernard Ingham she devised a sketch, which she would perform at the ceremony with Eddington and Hawthorne in front of the media.

When she arrived at the venue, she told waiting journalists they would be witnessing "the premiere of Yes, Prime Minister".

At that stage, the writers hadn't even considered sending Hacker to Downing Street. The actors - neither of them admirers of Mrs Thatcher - didn't want to do it. Neither, though, wanted to provoke her displeasure by saying no.

Image caption Co-writer Jonathan Lynn went on to a career in Hollywood

Image caption Sir Antony Jay was very well-connected in the world of politics

In the 30 years since, Jonathan Lynn has lived in the United States, writing for the big screen and directing films, including My Cousin Vinny. Despite his experiences in Hollywood, he's still astonished by the time and resources lavished on the awards ceremony sketch, including blanket coverage by the media.

"They rehearsed it at Number 10 23 times. My reaction was: 'what the hell?, why weren't they running the country? What were they doing, rehearsing a sketch 23 times?" Then he pauses for a beat, adding with perfect comic timing, "A bad sketch".

He got his revenge when he and Jay accepted the award, congratulating the prime minister on "finally taking her rightful place in the field of situation comedy. It got, I think, maybe the biggest laugh of my career". Mrs Thatcher, he says, did not laugh.

Mrs Thatcher's sketch proposed the abolition of economists. In their version of life in Number Ten, Jay and Lynn got the laughs with more realistic scenarios. Some of them even went on to come true.

Image caption Former Downing Street insider Lord Donoughue checked scripts for accuracy

In The National Education Service - one of four complete episodes included in Humphreys And Hackers All - the prime minister considers giving parents the power to choose schools. The debate between the characters prefigures much of what was said during Tony Blair's attempts to change education.

"I actually remember a debate around the cabinet table", Mr Blair told me, "and people actually saying you shouldn't do that because then the other schools in the area who aren't performing adequately will feel very disgruntled by introducing this centre of excellence into the local community."

Mr Blair says his sympathies were always with his fictional Downing Street predecessor, Jim Hacker (whose political affiliations were never revealed), but he professes a sneaking admiration for Sir Humphrey Appleby.

Lord Donoughue, now a Labour peer, was Head of the Downing Street Policy Unit between 1974 and 1979. He suggested ideas for Yes, Minister and Yes, Prime Minister and checked the scripts for accuracy.

But he says some of his fellow ministers in Mr Blair's government had paid a bit too much attention to the programme.

"It either made politicians and ministers sort of wary of taking civil advice, or because it demoralised a bit the civil service", he says, noting that some of his ministerial contemporaries, having watched Sir Humphrey's attempts to manipulate Hacker would sometime refuse to take sound advice.

The fictional Prime Minister Hacker has had four real life successors.

David Cameron, the latest, studied government at university.

"I once had to write an essay on 'How true to life is Yes, Minister'", he recalled. "I think I wrote… that it wasn't true to life. I can tell you, as prime minister, it is true to life."

Shaun Ley presents Humphreys And Hackers All on BBC Radio 4 extra, on Saturday morning at 0900 GMT and again at 1900 GMT. It will also be available on the BBC iPlayer.