A pregnant Irish teenager won her high court battle in Dublin today to be allowed to travel to Britain to have an abortion.

The 17-year-old, known as Miss D in court, is four months pregnant with a baby who has anencephaly, meaning a major part of its brain, skull and scalp will not form.

After being told two weeks ago that the baby was not expected to survive for more than three days at the most after birth, Miss D told a social worker she could not cope with carrying it.

The Irish Health Service Executive stepped in and put the 17-year-old, who is from the eastern province of Leinster, in its care and prevented her from making the journey.

The executive prompted a legal battle by informing police that it wanted officers to stop her from travelling and wrote to the Passport Office refusing its consent for a passport.

Abortion is illegal in the Republic of Ireland unless the mother's life is in danger and the executive argued that the laws did not permit a termination on the grounds of foetal abnormality.

However, Mr Justice Liam McKechnie ruled today that there were no statutory or constitutional grounds for stopping her from travelling to the UK for the operation.

The case has exposed the confusion in the Republic's abortion laws and has shown government agencies at odds with one another over the legal complications.

In court last week, the executive made a U-turn and dropped its opposition to her travelling to the UK, and said it would let her go on the grounds she has consent from her mother and a judge. But the process was further protracted on Saturday when a district judge refused to give consent.

Also during the hearing, the court heard from a barrister, appointed by the state to represent the unborn child, who maintained that the foetus - regardless of medical evidence that it will not survive - still had rights and was protected under the constitution.

The lawyer said the courts - and any state agency, including the gardai - were barred from helping someone to seek an abortion abroad. However, he agreed there were no laws restraining the teenager from going to the UK.

Anti-abortion protesters and a pro-choice group staged rival demonstrations outside the court.

A number of support groups sympathetic to the plight of Miss D welcomed today's ruling. Both the Irish Family Planning Association and the Alliance for Choice group said the teenager should not have had to endure a protracted court hearing.

The family planning association said the proceedings had delayed the girl's access to a termination, as well as causing undue stress to someone already dealing with the trauma of the diagnosis given for the foetus.

Alliance for Choice spokeswoman Dr Mary Muldowney said: "Alliance for Choice asks how many more young women will be traumatised before Irish law recognises their human right to access abortion services safely and legally in their own country.

"Most of the stress that surrounds abortion for women from this country relates to the barriers that the current legal situation has erected around women's ability to make choices based on what is right for them."

It is estimated that around 7,000 women cross the Irish Sea every year to terminate unwanted pregnancies in the UK.