The five-month court battle over the future of runaway schoolgirl Misbah Rana appeared to be over yesterday after her estranged parents came to an agreement.

Misbah, 12, also known as Molly Campbell, will go on living in Pakistan with her father, and her mother will have to go there if she wants to see her. Under the compromise, her former husband has agreed to bear her expenses.

Previously, Louise Campbell had been insisting her daughter, Misbah, would be able to visit her on Lewis, which the girl fled last August to the Pakistani city of Lahore to be with her father.

"The matter is over for all time to come, at all courts," Abdul Qayyum, the lawyer of Sajad Ahmed Rana, said after a hearing in the Supreme Court in Islama-bad. "The compromise is that all cases by all parties will be withdrawn."

Under the deal, Ms Campbell can visit her daughter and two sons living with their father at any time.

Mr Rana also assured the court he would allow Misbah to visit Scotland whenever she wanted, though the girl said she had no desire to return.

"I don't want to go," Misbah told the court, while standing next to her father.

Wearing a white headscarf, the beaming girl told reporters she was overjoyed at the compromise. "I am very happy, praise to Allah, I can stay in Pakistan with my family and now I can get on with my life, I can study, I can go school."

Asked if she planned to travel to Britain, Misbah said: "My mum will come and visit me here. I am not going to go there."

Western Isles MP Angus MacNeil said: "I hope peace is returning to what is a unique and difficult family situation and that both parents will now work together, for the sake of their children.

"I wish the family all the best for the future. Molly, or Misbah, seems quite settled in Pakistan but she would, of course, always be welcome back in the Western Isles."

A previous ruling at the High Court in Lahore stated Misbah should be handed over to the British authorities and returned to live with her mother in Scotland, where the courts had previously awarded her custody.

That ruling was dismissed by Judge Mohammed Chaudhry. He said both parents had agreed the mother would be free to visit Pakistan to see her daughter, with expenses paid by her father. Ill health and financial problems have prevented Ms Campbell from visiting Pakistan for any of the court hearings.

Misbah has been living with her father since fleeing with him to the eastern city of Lahore in August from her mother's home near Stornoway.

The child's mother was not at court but her lawyer, Ms Nahida Mahboob Ellahi, said: "Between the two of us (lawyers) we reached the agreement which was accepted by both sides. Mr Rana said he will pay for flights and accommodation for Ms Campbell to visit Lahore.

"She will also be allowed contact by phone and the internet. Molly will be free to return to Scotland any time she decides to in the future."

Hopes of breaking the deadlock in the bitter legal wrangle had stalled on Wednesday when Mr Rana, 45, rejected conditions proposed by his ex-wife for access rights.

But Ms Campbell's lawyers said their client would drop her demand for full custody in return for regular contact by phone and e-mail with her daughter, as well as visits to Scotland during the school holidays.

Her ex-husband had been opposed to his daughter visiting her mother as he said his ex-wife was now living with a non-Muslim man outside of marriage, and this was a sin in the Muslim faith.

The custody battle began after Misbah's 18-year-old sister, Tahmina, met her outside her Stornoway school on August 25 and went with her to the airport.

Ms Campbell, 38, claimed in her legal petition in Pakistan that Misbah had been abducted by her former husband and eldest daughter.

She was awarded interim custody at the Court of Session in 2005 and had been applying to make that arrangement permanent. But Misbah repeatedly insisted she wanted to remain in Pakistan with her father.

Mr Rana and his ex-wife were married in a Muslim ceremony in Glasgow in 1984 and had two sons, Adam, 16, and Omar, 21, and two daughters, Tahmina and Misbah.

After the marriage broke down, the children lived with their father and moved to Pakistan but later returned to stay with their mother.

A spokesman for the Crown Office said the court case in Scotland which awarded custody of Misbah to her mother had been a civil action and was "not a matter we can comment on". He said any question of prosecution of Mr Rana, if he returned to Scotland, for defying the court order, could only be speculation.