The kidnappers had forced me to lie face down on the floor. But after they left, and the small, bare room had fallen silent, I rolled over and pulled myself slowly into a sitting position.
My wrists were handcuffed behind my back, and a black hood had been pulled down over my head. And as I sat there - in danger, and afraid - I had a great sense of being at the very lowest point of my life.
It had begun out in the spring sunshine, on the streets of Gaza City.
A saloon car had suddenly surged past mine, and then pulled up, forcing me to stop.
A young man emerged from the passenger side and pointed a pistol at me.
I had reported many times on the kidnapping of foreigners in Gaza. Now, as I always feared it might, my turn had come.
The figure with the pistol and another gunman forced me into their car, and as we sped off I was made to lie on the back seat.
In the claustrophobic, intense, violent, sliver of land that is Gaza, there was now a shadowy organisation that thought in terms of waging Jihad on the West
A hood had been shoved over my face, but through it I could see the sun flickering between the tower blocks. I could tell that we were heading south and east, towards the city's rougher neighbourhoods.
Most kidnappings in Gaza used to be carried out by disgruntled militant groups seeking the attention of the authorities in some minor dispute.
And always the Westerner was freed within a week or so, shaken but unharmed.
But the game had changed last summer.
A much more sinister group had emerged and seized two members of a team from the American Fox News network.
They were freed, but only after making a video-taped denunciation of the West, and a public conversion to Islam.
Of course this was serious.
Gaza has a population of 1.5m
In the claustrophobic, intense, violent, sliver of land that is Gaza, there was now a shadowy organisation that thought in terms of waging Jihad on the West.
I knew it was likely to strike again, targeting the few dozen members of Gaza's foreign community. And so, with the help of the BBC's security experts, I did everything I could to reduce the risk of capture.
I moved to a better-protected apartment. I filmed less in the streets, and switched cars and made sure that my movements in the city were always random and unpredictable.
And set against the danger, I felt that Gaza's story was important.
It is at the centre of the Palestinian drama, which in turn lies at the heart of the rising tensions between the East and the West that have become the defining story of our time.
So, in consultation with senior colleagues, I decided that the risks were worth taking, and I stayed in Gaza.
And I did manage to keep out of the grasp of the kidnappers almost to the end. When the man with the pistol emerged from the white saloon, I had just 16 days left until I was due to leave for good.
The Jihadi leader
As I lay on a thin mattress on the floor, late on the first night of my captivity, the door opened.
Its frame was filled by a tall figure in a long white robe.
He stood for a moment, looking down at me - swathed in a red-chequered headdress that completely masked his face. The Jihadi leader had arrived.
He stepped into the room and sat down heavily in a white plastic chair.
"Alan Johnston," he said in English. "We know everything."
He said that my kidnapping was about securing the release of Muslims jailed in Britain.
Later, my captors - the Army of Islam - would describe me as a prisoner in what they see as the war between Muslims and non-Muslims.
When I started to say that Britain would not negotiate, the man in the chair cut me off. He said that the British would be forced to listen.
But mostly the voice emerging from the mask was calm, and even kindly.
I was left with a disturbing sense that what was about to happen would be protracted and life changing
He said that I would not be killed. That I would be treated well, in keeping with Islamic codes of conduct towards prisoners.
Crucially, he said that I would eventually be allowed to leave. I asked when, but he just said, "When the time is right."
Did he mean weeks, or months, or longer? It was impossible to say.
But I was left with a disturbing sense that what was about to happen would be protracted and life-changing.
When it was over, he said, I would write a book about my experience, and even that I would finally get married.
But how far could I trust the masked man? Did his word really count for anything? Could he simply change his mind?
And I wondered if he really was a leader of the group. Perhaps, in reality, others would decide my fate.
I did fall asleep again, but I was woken by two men coming into the room.
I had been stripped of my watch, and could only tell the time by the passage of the sun, and the five calls to prayer from nearby mosques
They handcuffed me and put the black hood back over my head, and led me slowly out into the cold of the night.
There was no word of explanation, and as my mind searched for one in that terrifying moment of uncertainty, I feared, as I walked into the darkness, that I might be going to my death.
That I was being taken somewhere to be shot.
My first cell
But the tension eased as I began to realise that the men were only moving me to another building and what would - for a time - become my cell.
In that room, on the roof of an apartment block, there was just a narrow, sagging bed and two plastic chairs. There was no television, or radio, or book, or pen, or paper.
I had been stripped of my watch, and could only tell the time by the passage of the sun, and the five calls to prayer from nearby mosques.
As one empty day slid slowly into another, the seriousness of my situation became more and more apparent
I had had to throw away my disposable contact lenses on the first day, and my eyes are very weak.
And so, in this blurred, empty room I began to try to come to terms with the disaster that had engulfed me.
I paced backwards and forwards across the cell. Five strides, then a turn, and five strides back. Mile, after mile, after mile.
Imagine yourself in that room.
Imagine pacing, or just sitting for three hours, for five hours, for 10 hours. After you had done 12 hours, you would still have four or five more before you could hope to fall asleep.
And you would know that the next day would be the same, and the next, and the one after that, and so on, and on, and on.
As one empty day slid slowly into another, the seriousness of my situation became more and more apparent.
It is hard to strike at Britain from Gaza. There is no British business there, and the British Council library was burned down last year by an angry mob.
Almost all that Britain had left in Gaza was the BBC. And in the BBC, there was only one British citizen, me. And the Jihadis had me, like a bird in a cage.
Britain never does deals with kidnappers, so why - I could not help worrying - would I ever be freed?
I thought of the Western hostages who had been held for years in Beirut in the 1980s, and I wondered if their fate might now be mine.
The first crisis came in the form of a bout of illness.
The food was quite reasonable, Palestinian-style rice or bean or vegetable dishes apparently cooked in a flat just below my room.
I was frightened that I would just get sicker and sicker
But my European stomach could not cope either with what I was eating, or the dirty water.
Soon I could feel a swelling just below my ribs, and there were many trips to the small, foul-smelling toilet attached to my room, where the floor was always awash with water.
I was frightened that I would just get sicker and sicker, and I decided I must try to get some control over my diet.
In the first weeks I had occasionally been given potato chips, and I knew that even the toughest Gazan bacteria could not survive the sizzling oil that they were fried in.
So I asked just for a plate of chips each day, and for my water to be boiled.
And those simple elements, along with bread, tomatoes, some fruit and later eggs became the basis of my rather dull but safe two meals a day.
There was, though, never quite enough food, and I eventually lost 10kg (22lb).
I felt very, very far from home, trapped, and aghast at how dire my situation was
And always I worried - especially when I had a serious allergic reaction later on - that I might fall dangerously ill.
I was sure that, if it came to it, the Army of Islam would just let me fade away slowly rather than call off the kidnap because I was sick.
Report of my death
In those first, terrible days - the hardest that I have ever known - I worried very much about the impact my abduction would have on my elderly parents and my sister at home in Scotland.
And of course, with that wonderful clarity of hindsight, I deeply, deeply regretted having stayed in Gaza so long and having taken the risks that I had.
One of my lowest moments came during a power cut.
I lay in a dwindling pool of candlelight, listening to the shouting, rowing neighbours and occasional gunshots that are all part of the noisy clamour of Gaza's poorer neighbourhoods.
I felt very, very far from home, trapped, and aghast at how dire my situation was.
Things were, however, just about to get a little better.
Desperate for some distraction to ease the psychological pressure, I had repeatedly asked for a radio, and amazingly, on the night of that power cut, a guard brought one into my room.
Suddenly I had a link with the outside world. A voice in my cell, and something to listen to other than my own frightening thoughts.
And through the radio I became aware of the extraordinary, worldwide campaign that the BBC was mobilising on my behalf. It was an enormous psychological boost.
And, most movingly, I realised that the vast majority of Palestinians were condemning the kidnappers.
Many people in Gaza seemed to appreciate that I had chosen to live among them for years in order to try to tell their story to the world.
But the radio also brought dreadful news.
In those calm, measured tones of the BBC, I heard reports of a claim that I had been executed.
I was sure that if I was to be put to death, the act would be video-taped in the style of Jihadi executions in Iraq
It was a shocking moment. I had been declared dead.
And I thought how appalling it was that my family should have to endure that.
But of course, I knew that I was far from dead, and after a few minutes I could not help recalling that famous Mark Twain line: "Reports of my death are exaggerated."
I was worried though, that perhaps the announcement of my execution was just a little premature. I knew that my kidnappers' demands were not being met, and I thought that perhaps they had decided to kill me.
I felt that I needed to prepare myself for that possibility in the hours ahead.
I was sure that if I was to be put to death, the act would be video-taped in the style of Jihadi executions in Iraq.
My guard barged into my room with a set of manacles
If that was to be the last image my family and the world was to have of me - if at all possible - I did not want it to be one of a weeping, pleading, broken man.
So through that long night, I lay listening to every sound that might signal the coming of my assassins, and tried to gather the strength that I would need if the worst were to happen.
But at last the silence was broken by the dawn call to prayer. The night was over. Somehow I felt that the danger had passed, and I fell asleep.
But that was not the last time that death seemed a possibility.
Threat to kill me
A few weeks later my guard barged into my room with a set of manacles.
My wrists and ankles were chained together. And the guard shut my window, and put off the light, leaving me in the dark to swelter in Gaza's summer heat.
He told me that it was being decided whether I should be put to death in the days ahead. If that was to happen, he said, my throat would be cut with a knife.
I did not quite believe the threat, but again, I had to prepare myself for the worst.
I am sure that different people approach something like that in different ways.
But I chose to rehearse in my mind exactly what might happen, hoping that somehow that would make the lead-up to any execution a little less shocking, a little less terrifying, and hoping that that might make it easier to preserve some kind of dignity in my final moments.
But mercifully, the crisis passed. In fact, the chains came off after just 24 hours, and as the days went by, the threat of execution seemed to recede again.
Through all this I gradually came to know my guards.
One of them, a man in his mid-20s called Khamees, with a dark, quite handsome face, would be with me almost every day. Right through to the kidnap's frightening climax.
Khamees had matured into a battle-hardened, urban guerrilla.
Like many young men who I had met in Gaza, Khamees was the son of a family that had either fled or been driven from their home in what is now Israel.
He had been raised in the poverty of one of Gaza's intensely crowded cities, and been drawn to the militant groups that had fought the occupying Israeli army.
Khamees had matured into a battle-hardened urban guerrilla.
He walked with a limp and had a slightly misshapen torso, the legacy of a wound inflicted by the Israelis. But they were not his only enemy.
He had trouble too with both of Gaza's main factions, Hamas and Fatah.
After worrying about them so much it was a vast relief to see my father make a powerful and dignified address
He was a wanted man, and he almost never left the succession of flats that were my prisons.
He lived confined to the shadows - almost literally, in the second of our hideouts - where the shutters on the windows were kept closed and I did not see the sun for nearly three months.
Khamees would exercise by pacing up and down the gloomy corridor, counting the laps on his prayer beads.
He spent countless hours flipping through the Arabic satellite television channels, and often, far into the night, he would sit in a pale blue robe, reading aloud from the Koran.
Occasionally he would let me go through to his room and watch television for an hour or two.
And one day he allowed me to see my parents make a televised appeal for my release.
After worrying about them so much, it was a vast relief to see my father make a powerful and dignified address. And although my mother did not speak, when I looked into her eyes I was somehow sure that she too had the strength to cope.
I felt very bad at having brought the worst of the world's troubles crashing through my parents' peaceful lives, far away on the west coast of Scotland.
My kidnappers - the most frightening kind of people - were putting them under appalling pressure, and all of Britain was watching.
But my parents were not being broken. They were, in Dad's words, "hanging in there" - and for me, it was their finest hour.
To let me see my parents on television was an act of kindness on the part of my guard. And there were certainly others.
Dark and violent guard
In the second of our four hideouts - where I was held longest - Khamees allowed the regime to become quite lax.
A number of times, tiny things sent Khamees into frightening rages
My door was left unlocked so that I could go to a bathroom and even use a kitchen next to my room, where eventually I was boiling water and fixing very simple meals for myself twice a day.
And there were moments when Khamees would be friendly, when we would talk a little about Gaza, and about politics or Islam.
But mostly I will remember Khamees as a dark and moody figure.
Often, for days at a time, he barely spoke to me, refusing to respond if I said hello.
Handing me my food, he would just glare at me hard, saying nothing, and a number of times tiny things sent him into frightening rages that I came to dread.
It was often easy to imagine that he saw me as a great burden, and that he loathed me.
And when he smashed me in the face in the final moments of the kidnap, I felt that with Khamees, perhaps, all along violence had never been far below the surface.
As the weeks drifted by, and I paced through my wasteland of time, my thoughts often ranged back across my life.
I filled many empty hours reflecting on periods in my childhood and phases of my career.
I tried to work out the roots of certain aspects of my character. And I thought hard again about why one or two particularly important relationships in my past had worked, but then eventually lost their way.
But much of my mental energy went into the huge effort to confront my many anxieties, the struggle as I saw it, to keep my mind in the right place.
I tried to strangle damaging, negative thoughts almost as they emerged, before they could take hold and drive me down
I felt very strongly that in the kidnapping I was facing the greatest challenge of my life, and I knew that I would perhaps always measure myself by the way I met it, or failed to meet it.
I told myself that in my captivity there was only one thing that I might be able to control - my state of mind.
And I struggled to persuade myself that bouts of depression did nothing to change the hard realities of my situation, they only weakened me.
I tried to strangle damaging, negative thoughts almost as they emerged, before they could take hold and drive me down.
And positive thoughts had to be encouraged.
Of course, at first glance, there was not much to take heart from in my situation.
But the fact was that I had not been killed, and I was not being beaten around.
I was being fed reasonably, and I decided that my conditions could have been much, much worse.
Whatever else it was, my Gazan incarceration was not what Iraqi prisoners had been forced to endure at Abu Ghraib jail.
It was not the Russian Gulag, and it certainly was not the Nazi death camps.
I felt that I would not be able to pick up a book again about the Holocaust without feeling a sense of shame, if I were somehow to break down mentally under the very, very, very much easier circumstances of my captivity.
I thought too that, unfortunately, every day around the world, people are being told that they have cancer, and that they only have a year or two to live. But the vast majority of them find the strength to face the end of their lives with dignity and courage.
I, on the other hand, was just waiting for my life to begin again, and I told myself that it would be shameful if I could not conduct myself with some grace in the face of my much lesser challenge.
And in its search for inspiration, my mind took me down what may sound to you like some rather strange paths.
But for me, as impressive as any story of endurance, is that of the explorer, Ernest Shackleton.
Shackleton and six of his crew spent 16 days crossing 1,300 km of ocean
After his ship was crushed by the Antarctic ice nearly a century ago, he took a tiny lifeboat and set out across the great wastes of the stormy Southern Ocean. He aimed for an almost unimaginably small island far beyond his horizon, and eventually he reached it.
And in my prison, I felt that I needed some kind of mental lifeboat, to help me cross the great ocean of time that lay before me, aiming for that almost unimaginable moment far beyond my horizon when I might somehow go free.
And so I took all the positive thoughts I could muster and lashed them together in my mind, like planks in a psychological raft that I hoped would buoy me up.
And in some ways it did. It was one of several mental devices, or tricks, or props that helped me get through.
In this way, I fought what was the psychological battle of my life.
God knows, it was hard, and lonely, and there were many dark passages when I edged close to despair.
But I was always in the fight, and there was no collapse.
Eventually Gaza's violent politics suddenly shifted against my kidnappers.
The powerful Hamas and Fatah factions began a fight to the death. Hour after hour, I lay listening to machine gun and rocket fire in the streets around the apartment block where I was being held.
Bad enough, I felt, to be kidnapped, but worse still to be lost in a place that had descended into all-out war.
Eventually though, Hamas managed to seize complete control.
It immediately set about imposing what it would regard as order on Gaza, and it made ending my high-profile kidnapping a priority.
For the first time, my captors seemed shaken, and uncertain - but they had a plan.
Khamees came into my room with a plain, black briefcase, of a kind that you might see any accountant carry on the London underground.
The Army of Islam released two videos of Alan Johnston
But he opened it to reveal a suicide bomber's vest, with panels of explosives that closed tight around my stomach as I pulled it on.
In a letter, the leader - the masked man from the first night - said that I needed to be afraid.
He said that Hamas was planning an assault that would turn the hideout into what he called "a death zone".
The message I had to give via a video camera - dressed in my deadly contraption - was that if there was an attack, I too would die.
But still Hamas was closing in, and the Army of Islam prepared for a showdown.
A machine gun nest was set up just under the room where I was being held. And I could hear the group's fighters scramble to their battle stations below me, during an exchange of fire, as Hamas forces probed their defences.
I knew that if Hamas stormed the apartment block it would come with all guns blazing, and I might well die in the assault.
And even if Hamas did not kill me accidentally, there would be a danger that the kidnappers - furious and frightened and about to die themselves - might shoot me to prevent me being rescued alive.
Then suddenly, late one night, I was taken downstairs.
A hood was put over my head, and I was led stumbling out into the darkness as members of the gang began to hit me and slam me against walls and the side of a car, before I was shoved into its back seat.
The kidnappers and the powerful clan that was protecting them, seemed to have buckled under the Hamas pressure. They had agreed to deliver me up, in return for their survival.
But I did not know that, as the car began to move slowly towards the Hamas lines - and the most terrifying ride of my life began.
It seemed that a gun battle might erupt at any moment and the car would be filled with bullets
My guards, with their Kalashnikov rifles on either side of me, were screaming angry - furious, no doubt, at the failure of the kidnap and scared, perhaps, that Hamas would kill them anyway, whatever the deal.
Khamees struck at my head, and I could taste blood in my mouth.
At one of the checkpoints, through the wool of my mask, I could see the muzzle of a rifle inches from my eye and I knew that the guard on my right was roaring that he would put a bullet in my brain if the Hamas men did not back off.
In the extraordinary tension and the confusion it seemed that a gun battle might erupt at any moment and the car would be filled with bullets.
I'm going to be fine
Eventually we came to a halt, and Khamees dragged me out into the road.
Alan's friend Fayed Abu Shamalla (right) was present at the handover
I looked up to see the alleyway filled with armed men standing in the street light. Two of them stepped forward and led me away.
I was afraid that this was some new gang to which I had now been passed on.
But actually these were Hamas men, and as we turned a corner, there, standing in a garden, was my old friend and colleague, Fayed Abu Shamalla of the BBC Arabic service.
Only then did I know that my kidnap was over, and that I was free.
Days later, I was back in Scotland, taking that road that I know so well - heading at last for the hills of Argyll, and my family.
And there, in our house by the sea - in that beautiful, peaceful place - all that happened to me in Gaza began to slide into the past.
But the experience of incarceration does have a way of lingering, of haunting the nights.
I dream sometimes that I am in captivity again, and I cannot tell you how good it is to wake and gradually realise that, actually, I am free. Safe, back at home, on the shores of Loch Goil.
But the nightmares come less frequently now. And although psychologists might say that these are still quite early days, I very much believe that I am going to be fine.
Alan returned to the UK on 7 July
And the kidnap's legacy is not all bad.
With its locks and chains, its solitary confinement and moments of terror, it was a kind of dark education.
I lived through things which before I would have struggled to imagine and maybe, in the end, I will be stronger for that.
I have gained too a deeper sense of the value of freedom.
Perhaps only if you have ever been some kind of prisoner, can you truly understand its worth.
Even now, more than three months after I was freed, it can still seem faintly magical to do the simplest things, like walk down a street in the sunshine, or sit in a cafe with a newspaper.
And in my captivity in Gaza, I learnt again that oldest of lessons. That in life, all that really, really matters, are the people you love.