MADISON, Wis. -- About 50 pro-union protesters peacefully left the state Capitol late Thursday after a judge ruled they could no longer spend the night to show their opposition to Gov. Scott Walker's proposal to eliminate nearly all collective bargaining rights for public workers.

The judge also ruled the state had violated the public's free speech and assembly rights by restricting access to the building.

The protesters demanded to see a written copy of the order before they would go. University of Wisconsin-Madison Police Chief Susan Riseling read the order to the crowd, eliciting cheers when she read the judge's determination that the state had unconstitutionally restricted access to the building.

"We won this battle," said former Attorney General Peggy Lautenschlager, who represented unions that had challenged the state's decision to limit building access. But she also told the demonstrators they needed to leave.

Capitol Police Chief Charles Tubbs repeatedly urged the crowd to leave peacefully.

"I don't want to see anybody arrested," he said.

Ultimately, the protesters left without incident, exiting to the beat of drums and cheers from supporters who greeted them with hugs and high-fives outside the doors. There were no arrests.

The drama played out after Dane County Circuit Judge John Albert 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.

"We decided we didn't want to stoop to the level of Scotty and his minions. We decided it would be best for our image to leave tonight peacefully and come back tomorrow," said Matt Rowe, 21, of Madison, carrying an armful of blankets after he left the building.

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, Tubbs, the Capitol police chief, addressed the crowd, asking members of the mock funeral procession to leave and gathering the remaining protesters into the Rotunda. A debate ensued among protesters as to whether they should stay or go.

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.

Riseling, the university police chief, 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.

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.

Lautenschlager 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.

---

Associated Press writers Scott Bauer and Jason Smathers contributed to this report.