Pro-union protesters have vacated the Wisconsin Capitol on the 17th day of round-the-clock demonstrations after a judge ordered the building closed at night.

About 50 protesters left the building peacefully Thursday night about two hours after a judge ruled the state had unconstitutionally restricted building to the access. But the ruling also said the protesters had to leave Thursday night.

That led to a sometimes tense two hours as police and the attorney who represented the unions who fought the policy to restrict access to the building urged them to leave peacefully.

The protesters are part of demonstrations against a bill pushed by Republican Gov. Scott Walker that would strip most public employees of most of their collective bargaining rights.

Dane County Circuit Judge John Albert had directed authorities to immediately take actions to remove demonstrators who stayed in the Capitol after its normal 6 p.m. closing time. He also ordered the removal of unauthorized materials, such as sleeping bags, air mattresses and the hundreds -- perhaps even thousands -- of signs that protesters have taped to the Capitol's walls.

Some protesters voluntarily complied with the order to leave. Others did not immediately do so.

The demonstrators are upset with Republican Gov. Scott Walker's proposal to eliminate nearly all collective bargaining rights for public employee unions. At times, tens of thousands of people have congregated on the Capitol grounds during the past couple of weeks. About 100 people ignored a 4 p.m. Sunday deadline to leave the building so it could be cleaned, instead sleeping on the floor and occasionally banging drums and chanting.

Since Monday, the Department of Administration has restricted public access to the building, generally allowing in more protesters only when an equal number left. Unions challenged the policy in court, leading to Thursday's night's interim order. The lawsuit could continue.

The decision was a partial victory for protesters, because Albert determined that the policy restricting public access violated constitutional rights and ordered the state to re-open the Capitol with greater public access by 8 a.m. Monday. Although it was not detailed in his written order, the judge issued an oral order in court allowing the administration to institute permitting procedures that limit the times and locations where rallies can be held in the Capitol.

"Free speech, protests, rallies should be allowed during the hours the Capitol is open and at any other time when either house of the Legislature is in session or any committee or government body is conducting a public hearing," the judge said. "But it is completely within the rights of the people who run the Capitol to prevent people from entering ... with sleeping bags, pillows, mats and blankets and intending to remain after closing hours."

As word of the impending court order spread, some protesters carrying coffins rushed in through the main Capitol entrance and were met by others with chants of "police stand down," as officers stood between them.

Eventually, Capitol Police Chief Charles Tubbs addressed the crowd, asking members of the mock funeral procession to leave and gathering the remaining protesters into the Rotunda.

"We need to bring this situation back to a situation of normalcy. So we can get this building open the right way," Tubbs told protesters. "So I'm asking you, as a person, to leave."

A debate ensued among protesters as to whether they should stay or go.

"It may be in our interests to leave," said Damon Terrell, 19. "I myself cannot do that. I will stay here and face the consequences of my actions ... even though those above me will not."

Stuart Levitan, a local radio host, tried to persuade protesters that staying only would lead to arrest and paint them in an unfavorable light.

"The more it turns into a drum circle, the more likely it is that the bill will pass" restricting union benefits and bargaining powers, Levitan said.

Albert's ruling came after three days of testimony from more than 30 witnesses, including lawmakers, Capitol staff and protesters. On Thursday, a firefighter recounted how a crew responding to an elevator emergency call initially was denied access to the building because it went to a different door than the one designated for the public. One of Walker's staff members, meanwhile, described how the deafening noise from protesters made it difficult to work.

University of Wisconsin Police Chief Susan Riseling testified that 41 rounds of .22-caliber ammunition were found Thursday morning scattered at several locations outside the Capitol. No guns were found with them.

"I don't like to see live ammunition outside when I have significant crowds," Riseling said. "You can't do much with live ammunition without the gun, but the presence of it doesn't thrill me."

Assistant Attorney General Steven Means, who is representing the Department of Administration in the lawsuit, had asked the judge to order the building closed for security purposes.

Union attorney Peggy Lautenschlager, a former Wisconsin attorney general, said in court that the request to close the Capitol was an overreaction to the discovery of the ammunition.

"For all we know somebody planted them there -- we don't know if it was a protester," she said.