On 26 May 2009, I had finished an interview at the UN Relief and Works Agency (UNRWA) headquarters in Gaza City and was taking photographs outside for a book I was writing about Palestinian identity. Visitors to the Strip were few and far between then, especially after the kidnap of the BBC journalist Alan Johnston by Palestinian militants in 2007. I'd worked with Alan at the BBC World Service, and after his abduction I put off going to Gaza for as long as I could. But after his release, and then Israel's bombing campaign and invasion the following winter, I needed to return. Mental health groups were reporting an epidemic of post-traumatic stress sweeping the Strip that no book about Palestinian identity could ignore.

That day as I crouched, snapping away, a finger tapped my back. I turned and hauled myself up to see a young, trim-bearded man in a red bandanna, smiling from ear to ear. He looked so pleased to see me that I automatically smiled back and said, "Ahlan wa sahlan" ("Greetings"). But the man, whom I will call Khalid, seemed in a trance. Still smiling, he held up a long, red-and-white-handled dagger. Then he unsheathed the blade, raised it above his head and plunged it towards my chest. A split-second of dissonance between the smile and the dagger broke with a jolt as I spun around and sprinted off down the street, yelling for help.

Palestinians are famously welcoming to foreign visitors, sometimes embarrassingly so. But this time, as if in a nightmare, everyone I passed on the street seemed to ripple towards the walls, which were high, ringed with barbed wire and had no doors. In my initial dash, I had got about 10 yards on Khalid, but he was younger than me, determined, and inexorably catching up. After 200 metres, I stopped at a road junction, unable to run farther without exhausting myself beyond any hope of self-defence.

As I shouted and pleaded for help from frightened-looking strangers, a bearded man peeped out from behind a doorway and frantically ushered me into a security compound. From inside, a Hamas policeman in a black uniform barged past me, the door swung shut behind him and two gunshots exploded deafeningly on the street outside. More officers spilled out after him, one offering me his pistol as he went – I declined – and Khalid was quickly overpowered and arrested.

Despite my lack of physical injury, I didn't sleep well after the attack. Death seemed to be everywhere and I would jump at the sound of a banged door. It felt as if someone had turned up the contrast and colour on the outside world. I feared that Khalid was an al-Qaida-style jihadist, but friends said he had been taken to a psychiatric hospital. So I carried on interviewing psychiatrists, taxi drivers and tunnel engineers, but tried to stay off the streets and began varying my daily routines.

The rumour that Khalid had been released began a week after the attack. Gaza's Hamas government often let Salafist offenders go, to assuage national-religious sentiments among its members, to convince them it was not going soft on the Islam agenda and to prevent more radical challenges to their authority. But if that also meant that Khalid wasn't mentally ill, my environment was suddenly more dangerous.

A Gazan journalist I knew went to the psychiatric hospital to inquire about Khalid's case for a possible story. She was berated by the clinic's director for her lack of Islamic dress and questioned as to why she was helping a non-Muslim. Khalid had already been freed. For a few days after that, I carried a pair of scissors in my back pocket, in case of another attack. They would not have helped much, but I felt an acute sense of vulnerability.

Hamas had an interest in protecting internationals, and its officers had saved my life. But there was an unpredictable element in the mix. The interior minister, Fathi Hamad, knew that I was Jewish from a disastrous interview the year before, which he had used instead to interrogate me about my motives for not converting to Islam. The cops who arrested Khalid also knew I was Jewish. My statement after the attack had been a straightforward affair, until the translating officer was asked to read my full name from my passport. A long pause followed his recitation of my second name, Isaac. "What?" the chief officer queried, and asked for my name to be repeated. The translator did so, using "Yitzhak" – a Hebraised version of Isaac. A longer and much more uncomfortable silence followed, before the officer asked for my address in Gaza. Shortly after that, two Hamas secret policemen took up a permanent presence in a car outside my apartment. It had never been much of a reassurance, but with Khalid's release it began to feel sinister.

When the border crossing at Erez reopened a few days later, I made a beeline for the exit, my interviews unfinished, never expecting to return. But the question of who Khalid was, and what circumstances led him to the UN building that day, stayed with me. It was a bit like walking out of a paranoid Hollywood thriller before the end. My political sympathies were definitively with the Palestinians, but the murder in Gaza of the pro-Palestinian activist Vittorio Arrigoni in April 2011 – apparently by would-be jihadists – demonstrated that this was no guarantee of safety. Khalid's smiling face was a blank canvas on to which I could project orientalist fears. But I did not want to live like that. And if Khalid was not a Salafi jihadist, I did not need to. So I launched my own inquiry.

Through notes I had taken at the time, and phone calls to people I knew on the Strip, Khalid was eventually located by a friend at the al-Mezan Centre for Human Rights. Khalid was a nationalist, not a jihadist, his family said. He was also a schizophrenic, with a story that put the UNRWA events in a wholly different, and more sympathetic, light. When Khalid's brother Asad eventually told my friend that Khalid would talk to me in a controlled environment, at his home, I agreed, despite my fears.

Arthur Neslen on Al-Azhar Road, Gaza, scene of Khalid's attack on him.

Gaza is situated within hermetically sealed borders that are just 8km by 22km. Within that, 95% of private sector industry has shut down, official unemployment runs at 45% and four out of five people exist on UN food aid. Walking into the Strip through Erez and its 200 yards of rubble-strewn no man's land has a through-the-looking-glass feel to it, a bit like a prison visit. Although I trust my friend's judgments about the safety of the interview, as Erez's steel gates clang shut behind me, I am still consumed by fear.

In the taxi to Khalid's apartment, I stare at passing tenement blocks as though for the last time and feel an overwhelming urge to tell the driver to turn around and head for the border. But sometimes the places of terror and safety are not where they seem, I remind myself. I never invited Khalid into my life but he is there now, and I have a place in his life, too. I tell myself that this is a chance to turn that space into a positive and healing one for both of us. In reality, I have already come too far to turn back.

And so, two and a half years after the attack, I find myself at arm's-length from a shoeless Khalid. He is smaller than I remember, but still stocky, and clearly disturbed. His eyebrows easily scrunch up like angry seagulls on his pitted brow, but his voice is quiet.

"I was born in Libya in 1982," he says. "We lived in Benghazi and Tripoli, but we moved a lot. My father was a teacher, so he worked in different countries. We were diaspora refugees." Khalid was a middle child of eight brothers and sisters. When he was 13, his family returned to the Palestinian territories, hoping for an independent state after the signing of the Oslo Accords.

His first contact with Israeli Jews came when the family arrived at the Allenby bridge crossing between Jordan and the West Bank. "We were separated," Khalid says. "They took my sister and brother aside, and I think they blackmailed them. They wanted them to do things that the Israelis thought were right – but they were wrong. That was an assault on the family. It was a bad thing that they did." Asad disputes Khalid's "blackmail and collaboration" interpretation of events, but even suspicions of treachery in Gaza can be a black mark on a family's honour.

In Gaza, Khalid found it "a little difficult" to build relationships after leaving his friends in Libya. His family did not have ID cards and every trip they took along Gaza's north-south Salah ad-Din road was perilous. "If we were captured at a checkpoint, we ran the risk of being deported," Khalid says, and he runs his hand over his head, agitated. "It wasn't safe for us at all, so we decided to move again."

As the 1990s dragged on, Khalid became politicised by the second intifada – an uprising for Palestinian statehood that began in September 2000 – and increasingly withdrawn. "I finished my secondary education, and went to university [the Al-Azhar University, 100m from the UNRWA building]," he says, knitting his fingers into a cat's cradle. But he dropped out after two years. "I could just see more destruction and murder of Palestinians."

Khalid's unaligned political beliefs took on a religious tinge, even if his own prayer patterns were fitful. His primary political motivation was to recover all of pre-1948 Palestine. "I always liked fighting the occupation," he tells me with bravado.

What is the best strategy, I ask.

"Jihad," he replies instantly and flashes me an eye-to-eye stare. "The best way is through jihad, as the prophet Muhammad ordered all Muslims to do when non-Muslims occupy Muslim land." Still, he could be friends with non-Muslims, he says, "so long as they are not bad people who have come here to launch wars or hurt people".

In Khalid's bare salon, a young cousin appears with a tray of hot mint tea, and I notice a wreath of funereal-looking flowers in one corner. Tell me about what happened to you during Operation Cast Lead, the 2009 invasion, I ask him.

"On the first day, there were attacks across Gaza and I saw martyrs falling everywhere, including good people who fought the occupation," Khalid replies. As the bombing increased and the death toll rose, he heard a despairing Gazan on TV pleading for ambulances and political acts of help. When the Israelis came to a nearby neighbourhood on 12 January, "I thought that I must go there and ask them to stop their escalation. The soldiers pointed their guns at me and ordered me to strip. They handcuffed me so tightly that my wrists bled for an entire day. Then they put me inside the entrance of a house they were controlling so that every soldier who entered or left could hit me. They constantly swore, saying bad things about my family, and they beat me with their boots and rifle butts."

His arresting officer wouldn't let him eat or rest. "He made me stand near a window for two or three hours," Khalid says. "I was handcuffed and blindfolded, and I could hear very loud shooting from nearby. I was all the time standing there, and the officer was shooting from behind me."

In the district where Khalid was held, there were widespread accusations of the use of "human shields" – one such incident, three days after Khalid's arrest, led (unusually) to a conviction in an Israeli court – but Israel's policy of preventing Gazans from leaving the Strip to file lawsuits or give evidence against their army prevented Khalid from taking his case any further.

He remembers being forced by soldiers to march the next day, still blindfolded and handcuffed, and in a state of fear and exhaustion. He was then interrogated, and driven in an armoured vehicle to a detention camp. A pattern of questioning, strip searches, violence and humiliations ensued while he was dragged through Israel's military and judicial system. "I mostly remember being beaten by many people, on the way to court, even once in the court," Khalid recalls, pulling at his fingers. "While I was asked questions, I was beaten. When they told me to take my clothes off, I was beaten."

After one interrogation, he remembers signing a statement written by his jailers in Hebrew, a language he does not understand. Finally, in March 2009, he was taken back to the labyrinthine Erez border terminal and pushed through its metallic corridors into a Gaza that was by then 20% rubble. Two months later, I met him in Gaza City.

An Israeli justice ministry spokesperson confirmed the dates of Khalid's detention and release, and place of arrest. "During his investigation in the field by the IDF, he noted that he was active in Hamas and that he intended to perpetrate a suicide attack," their statement says, adding that no charges were ever filed against him.

How did he come to be outside the UNRWA building in May 2009? "I left home and went to the university that day," Khalid begins, blankly. "I waited for two hours with the knife. I saw foreigners in Jeeps, and I thought these were people who were participating in wars against us." UNRWA's employees are forbidden to walk Gaza's streets and must travel in armoured Land Rovers.

One of the things that helped me get over the attack, I told him, was knowing that he never stabbed me in the back when he had the chance. Khalid clucks his tongue. "I was very cautious to make sure that I didn't do something wrong," he says. "I was waiting for somebody who was part of the wars against us, and I saw this man with a camera.

"I approached him very closely," Khalid goes on, "to make sure that this was a person who had hurt us. When I pulled the knife, he ran away. I didn't want to warn him. I wanted to see that this was a person who was fighting against us. The person ran away and was crying, 'Help, help, help' and there were men who fired in the air and took the knife from me and took me to the police station. Maybe it was you?"

Since my barmitzvah, I had never felt that I looked particularly Jewish. At school in east London in the early 1980s, I was frightened that appearing Jewish would make me a target for attack. More than once, it did. Still, I never denied being Jewish and fought my corner when faced with violent antisemites. But I cannot see Khalid as one of those. What was it about me that made him think I was one of the people fighting against the Palestinians?

"I don't know," Khalid replies, exasperated. "It was strange, because usually these people are in cars and this man was walking. But the people who attack us are many – too many – and there is nothing we can do but to fight them back."

From beyond the window, a ghostly wail is seeping out of a mosque. "There was another incident on the anniversary of the war last year," Khalid continues coldly. "There was a big gathering. I went there with my knives. I saw a foreigner. I approached him. I stabbed him. The knife was weak and it broke. He didn't die. They arrested me again and then they released me the same day."

Asad later tells me that Khalid's description of the second incident was exaggerated, and that he had been arrested after acting aggressively and trying to hit the man.

As frightening as Khalid's words are, I do not react. Throughout our conversation, I have consciously tried to calm any tension by slowing my speech, lowering my tone, avoiding any outward sign of emotion. "The most important thing is that nobody told me that these people did not launch wars against the Palestinians," Khalid says. "Since then, I have understood that they did not and things have been better. There are solidarity people who come here to help. If they didn't hurt Palestinians, I would, of course, be happy to work with them and be friends."

At this, I lean forward and we embrace. As we do, I feel my shoulder blades instinctively tense. I realise that I don't actually know how I feel towards Khalid. His initial justification to the police after the attack on me had been that he thought I was "a Yahud [Jew] who had come to steal Palestinian land". Perhaps it was a plea for extenuating circumstances. The only Jews he had ever met were uniformed gunmen who brought with them fears of collaboration, expulsion and death.

I do not request an apology and none is offered. Khalid has been a diagnosed schizophrenic since 2007 and, Asad says, had never behaved violently before he was arrested during Operation Cast Lead. I can appreciate that his attempt to kill me was nothing personal.

His words are often ambiguous and our reconciliation has been as spartan as his family's apartment, but at least I have an explanation, and that helps a lot. Khalid has a human face to me again, and I hope that he feels the same way, too. The chain of trauma that linked us has been acknowledged, if not broken. I wish only that I could have told him that I was Jewish.

• Arthur Neslen is the author of In Your Eyes A Sandstorm: Ways of Being Palestinian and Occupied Minds: A Journey Through The Israeli Psyche.