The International Criminal Court could soon drop its demand that Saif al-Islam Gaddafi be transferred to the Hague for trial, officials have told the BBC.
They say the son of former Libyan leader Muammar Gaddafi could be tried inside Libya but under ICC supervision.
The argument over who should try him has been going on ever since his capture in November last year.
The ICC has indicted him for crimes against humanity, but Libya insists he be tried on its soil.
The Libyan justice ministry says a deal is being finalised under which Mr Gaddafi would be tried in Libya but with security and legal supervision provided by the international court.
The BBC's Jon Donnison, in the Libyan capital Tripoli, has been told by a Western official with good knowledge of the case that a deal is close to being agreed.
But the official warned it could be months before any trial might begin.
Describing the suggested arrangement as ground-breaking for the ICC, the official acknowledged concerns that 39-year-old Saif al-Islam could face the death penalty in Libya.
But he added that the court could accept a death sentence if the trial was fair and transparent, and there was an adequate appeals process.
The ICC's chief prosecutor Luis Moreno Ocampo is due to visit Libya this week.
The Libyan authorities have been refusing to hand Mr Gaddafi over to the ICC.
Human rights groups have argued that the Libyan justice system is not capable of dealing with such a high-profile case.
A lawyer involved in the case has described that view as patronising and colonial.
He told the BBC that the ICC should only try cases in which the country concerned was unwilling or unable to conduct its own trial.
Mr Gaddafi is currently being held by a militia in the Zintan region of Libya. He was once expected to succeed his father, Libya's late leader, Col Muammar Gaddafi.
The group has given no indication of when they will hand him over to the Libyan government.
Set up in 2002, the ICC made its first successful conviction last month, when Congolese militia leader Thomas Lubanga was found guilty of recruiting child soldiers.