An Alabama Baptist minister who confessed to having sex with married church members and neglecting to tell them he had AIDS was temporarily banned Thursday from acting as pastor.

Montgomery County Circuit Judge Charles Price issued a preliminary injunction, as sought by deacons and trustees of Shiloh Missionary Baptist Church. Price ruled that the Rev. Juan McFarland, 47, must turn in his church keys and his church-provided Mercedes and then stay away from the church he led for 24 years.

Church members hugged and prayed after the ruling. “Now we’ve got the church back, and the healing can begin,” said Lois Caffey, a member for 21 years.

After the court ruling, McFarland returned to the church, met with leaders in a private session they described as tense. Then he turned in his keys and left at 4:05 p.m. — less than an hour ahead of the judge’s deadline.

The judge scheduled a hearing Dec. 1 to decide whether to issue a permanent ban against McFarland.

The preacher confessed to his affairs, his AIDS diagnosis and said that he had been abusing drugs in a series of sermons that stunned church-goers.

Board of trustees chairman Lee Sanford said the challenge now is to reunite the 170 active members of the congregation. “I’m confident with God’s help we will be able to do that,” he said.

The plaintiffs in the lawsuit said the congregation voted to fire McFarland after his confessions but that he refused to leave and changed the church’s locks and control of church bank accounts.

McFarland said nothing inside or outside the courtroom Thursday during two hearings. He attended without an attorney. He also said nothing as he left the church carrying only a ball cap containing a few personal items.

The boards of deacons and trustees sued McFarland after he preached on Oct. 12 despite the vote to fire him a week earlier.

One of the plaintiffs, Deacon Nathan Williams Jr., said church leaders had no suspicions about McFarland until he delivered sermons in in August and September, during which he confessed to having sex with church members in the church building, but not in the sanctuary; having AIDS but not telling sex partners; and using illegal drugs. Williams and Sanford said McFarland told the congregation that God directed him to make a public confession.

Williams said that the congregation first tried to help the pastor but that when it didn’t work, members took a vote during a service Oct. 5 to fire him. He said some were upset that McFarland tried to fire several longtime church officials and others were concerned about taking communion from the ill minister or having him around their children.

Parliamentarian Marc Anthoni Peacock testified that the vote Oct. 5 wasn’t officially part of the Sunday service and he described it as “holy hell.” Peacock was originally a defendant in the lawsuit but resigned from the church Thursday and was dropped from the litigation.

Price said the courts have no role in religious matters, but they sometimes have to step in when congregations can’t settle their differences over control of buildings and money. “If it could be resolved in the church, it would have been already,” the judge told the courtroom packed, with more than 100 people.

Shiloh Missionary Baptist Church is 95 years old and is part of the National Baptist Convention. Church members on both sides of the pastoral dispute said the convention gives churches autonomy in personnel decisions.