Sara Ibrahim says that since the day her little sister Layla was sent to prison, her family has been faced with a simple choice: "Do we give up and just get on with our lives, or do we clear her name? And we've decided if it takes the rest of our lives, that's what we'll do – we'll clear her name."

It was a couple of weeks after she reported being attacked in the early hours of a cold January morning in 2009 that Layla Ibrahim, then 21, noticed a change in the attitude of the police. Yes, the police had documented the injuries to the back of her head and breasts, the black eye, the bleeding from her vagina. They had listened closely as she described the two strangers who attacked her, how the main perpetrator had worn a Nike hoodie, how she thought she had temporarily lost consciousness after being knocked to the ground, how she had felt a "thud" in her vagina but had no clear recollection of what had happened.

The police had seemed sympathetic as she explained how she tried to fend off her attackers with a pair of blunt scissors, and how the second assailant grabbed hold of them and started cutting her hair. Layla told them how eventually she had made her way home, running and bawling, almost feral with fear. The case quickly became high profile, as the local newspaper reported that the police had set up an incident room staffed by 30-40 officers and described it as "one of the city's biggest manhunts".

But a couple of weeks later it was as if the police were investigating an entirely different case, one in which the suspect was Layla herself. The police suggested she had acted in a strange manner when they first went to see her – crying one minute, laughing the next; that she had been aggressive. They talked about inconsistencies in her evidence.

At first Layla thought it understandable – of course, the police wanted to clarify what she had told them – but when they kept questioning her story, she became unnerved. She'd told them the batteries were flat on her mobile phone, but they seemed to think it odd that it wasn't working. And they told her the forensics suggested there was no soil on her clothing from the grass where she said she had been attacked.

"That's when I said I didn't want to answer any more questions without a solicitor," she writes in a letter from prison. "They asked why I wanted a solicitor and I said, 'Because I don't feel like I'm the victim.'"

It wasn't Layla who first heard the news her attack was no longer under investigation. Instead, the police contacted her mother at the school in Carlisle where she works as a senior teaching assistant to tell her they suspected Layla of fabricating her story and inflicting the injuries on herself.

"A detective came round and put all these photos of Layla's hair round the floor and said it looked to them as if she'd walked and cut her hair and dropped it," says Sandra Allen, Layla's mother. The DCI told her she thought the injuries to Layla's knee were suspicious. "I asked her what she meant, and she said, 'Well, it looks as if Layla just took something and slashed herself on the knee.' And I said it was winter, she'd fallen, it was iced – why would you think that?"

Layla was told she would be charged with wasting police time if she didn't drop the case. She refused – after all, she said, she'd been violently attacked. Eventually, the charge was upped to the more serious offence of perverting the course of justice. A year later, in June 2010, Layla – then six months pregnant – was convicted and sentenced to three years.

The story of Layla Ibrahim, now 23, is as bizarre as it is alarming. How can a woman end up jailed after reporting an attack on herself? And when there appeared to be powerful evidence of the savagery of the assault?

Layla had been out drinking with friends in Carlisle in early January 2009. They went on a mini pub-crawl, and she was drunk by the end of the evening but, she says, not out of control. She had no money left and says she asked her friend Richard Dent if he could lend her £10 or share a cab. When he refused, she was surprised but decided to walk home through a pathway by the River Eden known as the Cut.

Layla would later describe the two men who sprang out of the darkness as young – not much older than her own teenage brother – and said that the one whose face she saw looked like a drug addict with a "hollow, sucky-in face". She struggled home at around 4am, and banged on the door of her oldest sister Samira, who lives round the corner from her mother. Samira called the police, who arrived a couple of hours later.

We are chatting in Sandra's home in Carlisle as Layla's other sister Sara returns to the living room with a tray of drinks and chocolate biscuits. Sandra lived in Libya for many years with her then husband – the Libyan father of her children – and speaks fluent Arabic.

What troubles the family is the evidence they say could have proved her innocence. Male blood was found at the scene, but it was dismissed because it did not belong to one of the suspects and did not match anything on the DNA database. A male blond pubic hair was found on Layla that Rosemary Swain, the doctor who examined her, said would be crucial evidence against her attackers. But the family later learned it had been destroyed in the forensics lab.

The police did not take the cardigan Layla had been wearing for DNA testing. Although it was later handed in by the family, it had been lying around the house and might have been worn by other family members or even washed. Layla's shoes were not tested for DNA, although one shoe was alleged to have been held by an attacker. Her leggings were not tested for DNA, nor was her bra fully checked, although blood was found on it.

Layla's description of one of the attackers closely matched that of a suspect in other attacks in the area. Layla's family and a case worker who represented her believe that one of the many troubling aspects of her conviction is that while Layla is in jail, her attackers are out there, posing a threat to women.

The thing that did most to put Layla behind bars was the pair of scissors. Layla told the police how they were used against her by her attackers. The police claimed she had taken them with her to fake the attack. They pointed to the fact that Layla's DNA was on the scissors, as was fabric from her dress. But Layla says there is a straightforward explanation.

"Of course my DNA was on the scissors – they are my scissors," she writes. "I have always carried scissors with me since I was in school. I'm quite big-chested and my bras come undone because the metal bit inside comes out. My mum taught me to always carry scissors, needle and thread."

Asked about Layla Ibrahim, the director of public prosecutions Keir Starmer – who was briefed on the case after Sara visited him earlier this year but has so far declined to intervene – confirmed the scissors had been a crucial piece of prosecution evidence. "Much greater store was put on the evidence about the scissors than was put on the inconsistencies [in Layla's account of what happened]," he says.

As so often in such situations, the circumstances are confused. In her first statement, Layla said the second attacker had cut her hair, and it was only later, when running, that she discovered her dress was also torn. Layla later said the boys might have cut her dress, too – she simply couldn't remember. To complicate matters, Layla's mother Sandra had cut the dress under the armpit earlier that evening where it was tight.

The fact that Layla couldn't remember everything was an important part of the case against her, too. She doesn't dispute it; even today her memory of what happened is partial and muggy. "He [the first attacker] fell on top of me, and I don't really remember a lot after that. I woke up, well, it felt like I was waking up. And it hurt down below," she writes.

Layla’s sister, Sara ­Ibrahim, and her mother, Sandra Allen: 'All I want is someone to explain how my daughter can go through the horror of being attacked to end up in prison with her baby.' Photograph: Gary Calton

The family are wary of the police. Had they ever had cause to call on them before? Sara and Sandra look at each other, waiting to see who answers first.

The Ibrahims have always felt they stood out in Carlisle. Sara says when she was young there was only a handful of mixed-race families in the town. It wasn't always easy growing up there.

"I was brought up to respect the police," Sandra says. Her family is from Carlisle, she grew up here, later moving to Libya for work, where she met her husband. She returned to the UK when Layla was nine. But moving back with four mixed-race children brought its own problems. "My very first dealings with the police were when we came to England and that boy beat you up," Sandra reminds her daughter.

Sara laughs, quietly. "I had a few beatings because I was black. I can't remember which one you mean."

Sandra: "Sara got seriously beat up and the police didn't want to know. All the neighbours ran out, everyone was screaming and shouting. Sara's head was smashed up. The police came but didn't even look at her. It was just like 'these things happen'."

"They arrested me," Sara says, still bewildered all these years later. "In the scuffle, the boy got a scratch. We were so naive, the police asked us into the police station and me and Mum were like, 'Oh, they've just invited us in for a chat' and they arrested me! I was put on bail and we were back and forward to and from the police station."

Some time later, Sandra's son Taraq, then aged 12, had a series of run-ins with the police. He was arrested time and again by the same officer, but never charged. Sandra went to the Independent Police Complaints Commission. The issue was resolved by Cumbria constabulary, who admitted the officer had "targeted" Taraq "to deter him from committing crime".

Layla had no history of depression or self-harm before January 2009. A report by an independent psychologist, prepared for the court in advance of Layla's trial, concluded she was suffering from post-traumatic stress as a result of the attack, and found it difficult to explain why she would have fabricated it.

"Motives for false rape allegations have been found to be seeking attention or sympathy from others or revenge against others," wrote Carolyn John, a consultant clinical psychologist with 21 years' experience and the lead consultant for Newcastle Upon Tyne's acute adult mental health service. "I could find no motive for deliberate self-harm or for Ms Ibrahim having malingered. I could find nothing in her personality profile that might lead to attention-seeking or a lowered threshold for histrionic or antisocial behaviour that might amount to wasting police time."

John also pointed to various factors that undermined the evidence used against Layla. In terms of inconsistencies, she cited Layla's dyslexia as a reason for her mislabelling of left/right, and concussion following the blow to her head as a reason for her memory problems. John also raised the conditions in which Layla was interviewed: a lengthy process during which a male officer was present and she was not given anything to eat for hours.

Dr Rosemary Swain, a GP and specialist in sexual assault medical examinations who examined Layla shortly after the incident, reached the same conclusion, forming the view that Layla had indeed been subjected to a sexual assault. Despite working for the police, Swain would later give evidence in Layla's defence at her trial.

But the investigation into Layla continued. In February 2009, a month after the incident, Layla attempted suicide by throwing herself into a river. She was rescued by a passerby and taken to hospital where she seized a used needle and tried to cut her wrists.

Layla was identified as high risk and referred for a psychiatric assessment. The psychiatrist who assessed her did not find any mental health problems but instead enduring trauma resulting from the recent attack. "This is a 21-year-old woman with evidence of an adjustment disorder in relation to a sexual assault one month earlier," his report concluded. Sandra says Layla became desperate and despairing, unrecognisable from the daughter she knew.

Layla writes that while it is too late for her to be spared jail, one of the reasons she is determined to draw attention to her case is to help other women in the same position.

"We know of 30 women jailed for so-called false allegations of rape in the past 12 months," says Lisa Longstaff of Women Against Rape. "Such prosecutions must be stopped. It is a galling diversion for women to be jailed when the vast majority of rapists are not – 90% of rapes are never reported and only 6.7% of those that are reach conviction on a full charge of rape. The prosecution of women and the disproportionate media coverage they get are putting rape victims off reporting and leaving all of us more vulnerable to attack. Is that what they want?"

Starmer insists that discouraging women from reporting rape is the last thing prosecutors want. Under his leadership, the CPS last month published new guidance stating that individuals who retract rape allegations out of fear will be protected from prosecution. "Rape and domestic violence victims should be confident in reporting abuse without fear of prosecution if they are later pressured into retracting the allegation," Starmer said, responding to a controversial court of appeal case in which a woman had her prison sentence overturned after judges found she had been pressured into withdrawing a rape claim by her abusive husband.

Yet this new guidance offers no comfort for the likes of Layla Ibrahim: women who are accused of falsifying rape allegations still face prosecution. The guidance in fact states that prosecution is more likely when the allegation is believed to be made maliciously or over a sustained period of time – in other words, there is now an incentive to withdraw rape allegations if victims feel the police disbelieve them. Starmer has introduced a further check in the system, however, requiring all prosecutions against people accused of falsifying rape claims to be authorised by his office before proceeding. Would this have saved Layla? It's impossible to say, but he acknowledges that there may be women in jail now who would not have been prosecuted under the new regime.

One thing that would have stopped Layla from going to prison is if she had given in to the police's attempts to persuade her to withdraw her account of the attack. But Layla writes that she always felt confident that, as the victim, she would eventually be believed and was concerned that her attackers needed to be caught.

When her case came to court, Layla believes she was a disaster in the witness box. "I froze. I was like a rabbit stuck in headlights because I was beyond nervous. I didn't really understand what they were asking. I definitely don't think I did a good job."

There were other reasons Layla ended up being convicted, too. Her ex-boyfriend Nikki White, who had not been with her on the night, gave a statement saying they had argued (about a tomato sandwich). The prosecution argued she had faked the attack as a form of revenge. In his statement, he also said that Richard Dent, who had been out with Layla that night, told him afterwards that when he refused to share a cab home with her, Layla had said, "If anything happens to me, you will be sorry." Yet Dent made no mention of this when interviewed at the time, only confirming it was true in a second statement more than a year later.

Layla and her family believed there were criticisms to be made in court of the police investigation. But Jane Mayes, a caseworker at Geoffrey Clapp solicitors in Carlisle who advised Layla, points out that the tone of the trial was set by a horrific crime that had just happened in the area. On 2 June 2010, a local taxi driver Derrick Bird had gone on a shooting spree, killing 12 people. A couple of weeks later, when Layla's trial started, funerals were being held for those killed. A solicitor friend of both barristers and the judge had died in the shootings, and the trial was suspended for one day so they could attend the funeral. The police had been vilified in the national press for not stopping Bird earlier, and Mayes believes there was little appetite in court for further criticisms of the police. "Lots of little things went wrong at trial," she says, "but the massive thing was the Cumbria shootings. The atmosphere was extraordinary."

Instead, Layla's lawyers concentrated on her injuries. "The strategy was to show that the scientific evidence proved Layla couldn't have done it," Mayes explains. Five expert witnesses gave evidence for her. Forensic physician Dr Catherine White examined Layla's injuries – swelling to the back of her head, abrasions on her cheek, injuries to her breasts, scratches on her knee, damage to the perineum and bruising on her hymen. Most of these injuries, White concluded, "would be very unusual to have been [self-inflicted]… particularly in someone without a history of such in the past or a severe mental health problem."

Mayes says the prosecution managed to paint a brilliantly damning, but she thinks misleading, portrait of Layla. "Like her explanation of why she had the scissors. It made her look clever. Much cleverer than she is, poor Layla. Looked at in the whole, I think it's impossible she did it. But we lost every bloody point."

Although fresh counsel pointed out apparent flaws in the evidence, he advised the family there were insufficient grounds for appeal at present because of a lack of new evidence. Other barristers have expressed an interest in pursuing an appeal.

When sentencing Layla, Judge Paul Batty QC said: "Your behaviour throughout the proceedings has been irresponsible in the extreme and many would say wicked. You tore your own clothing, you cut your body with a pair of scissors, you feigned illness and injury. I'm entirely clear in this case that you craved attention. You wanted your friends to think they had left you in the position where they thought you were the subject of a serious sexual attack. You wanted to teach them a lesson."

When she heard the verdict, Layla collapsed. She was immediately remanded to the category A prison Low Newton in County Durham. "It was the worst place I've ever been to in my life," she writes. "You were among people like Rose West, and the Baby P killer, and you just think, 'What am I doing here?' They were eating dinner with us.

"I'd pretty much broken down by that point. I didn't eat, didn't socialise. They'd unlock my cell and I'd lock myself back up… I was getting called names because I'd been on the news, it was just horrible." After six weeks, Layla was sent to Durham infirmary where her daughter was born and a week later she was transferred to the mother and baby unit at the open prison Askham Grange.

Layla says it's her baby who has kept her going. "I'm a much stronger person now. After having her I had more to live for – my concentration's on coming out and giving her everything, getting a job." With good behaviour, she will be released in a few weeks on home detention curfew, required to wear a tag. But after struggling to overcome her dyslexia and obtain her childcare qualification, Layla's only hope of being able to work with children again is appealing against her conviction and clearing her name. "Childcare is now not an option," she writes. "I was also starting my NVQ in elderly care but neither of those are now possible."

While Layla has regained her strength, the past year has knocked the stuffing out of her mother. Sandra says she stayed strong until Layla was convicted, then she broke down. "In my mad times, nobody was allowed to drink coffee because Layla couldn't have it, nobody was allowed to eat, Christmas was cancelled, birthdays were cancelled." Did she want people to suffer like Layla? "Not suffer. Just share it. I think I was very, very close… to losing it. I never ate or drank for a week, I could hardly move at the end of it. I was constantly stuck in front of the computer trying to find someone who could explain how this happened to her. That's all I still want, someone to explain how my daughter can go through the horror of being attacked to end up in prison with her baby."

You can see the pain and exhaustion in her face. "How can you give my daughter three years, when she's never done anything wrong in her life? I still couldn't understand it if, God forbid, she had done it, but she hasn't. She's never been in trouble, she's worked hard, she's done everything right. Why was she sentenced to three years in prison? I can't understand it, and nobody will give me the answer."

Layla Ibrahim was released on home detention curfew last week after serving 13 months in jail.

• This article was amended on 15 August 2011. In the original, Jane Mayes's name was misspelled as Jane Meyes. This has been corrected.