BOSTON – A Boston man who has twice been convicted in a fatal bar stabbing may go to trial a third time after the Massachusetts Appeals Court on Monday found that his rights were violated because members of the public were excluded from a portion of jury selection during his second trial.

The Appeals Court reversed Joseph Downey’s conviction but prosecutors say they are prepared to put Downey on trial a third time if their appeal of the court ruling is unsuccessful.

Downey and his brother, Daniel, were convicted of second-degree murder in the 1997 killing of James Murphy inside a South Boston bar.

In 2004, a judge ordered a new trial, finding that the men’s attorneys agreed to wear microphones for a documentary without their consent.

The British film company Lion Television spent a year inside Suffolk County courthouses for the documentary, which was broadcast as part of WGBH-TV’s “Frontline” program in 2000.

The recorded conversations between the two brothers and their attorneys included discussions about possible guilty pleas midway through the trial.