Democratic mayoral candidate Bill de Blasio had to take time off the campaign trail to go to court yesterday, appearing before a judge over his arrest at a hospital protest.

Public Advocate De Blasio, City Councilman Stephen Levin and about a dozen nurses and others all had their disorderly-conduct cases put on a track to be dismissed if they avoid rearrest for six months. It’s a common way for Manhattan courts to resolve such cases.

De Blasio and the others were arrested July 10 after they ignored police orders to stop blocking the entrance to a Midtown office of the State University of New York, according to a court complaint.

The group was protesting SUNY’s plan to close Long Island College Hospital and sell its Brooklyn buildings.

“Civil disobedience is something you use when the normal governmental process isn’t functioning,” de Blasio said after his court appearance.

“I came to the conclusion that something more dramatic had to be done.” to bring attention to the issue, and I’m proud to say that I think it helped bring attention to the issue,” he said.

Since the protest, de Blasio has secured a court order to keep the hospital operating.The primaries are Sept. 10. The general election is Nov. 5.

De Blasio, who is positioning himself as the most liberal candidate in a crowded Democratic mayoral field, has been arrested at protests before, including at a 2003 demonstration over the closing of a Brooklyn firehouse. He was then a city councilman.

After polling in the middle of the Democratic mayoral pack for months, de Blasio had a slight lead in one poll last week. Another poll had him tied with City Council Speaker Christine Quinn.

He’s made hospital closings a major issue in his campaign.

Since 2000, 19 city hospitals have closed due to financial pressures, and a few others are now in trouble.

The protesters say the closures aren’t healthy for communities and overtax other hospitals. Some of the demonstrators were members of health-care workers’ unions.

“We need a plan to protect neighborhood hospitals,” de Blasio said yestersday.

Disorderly conduct is a violation akin to a traffic ticket, not a crime.