Sun has been at odds with his own city council from the day he took office this year -- the winner of a write-in campaign where he vowed to clean out what he called "corruption" at city hall. Department heads either quit or were fired.
He has already been ordered by a judge to start hiring new department heads for the city, and last week he escaped charges over allegations of criminal misconduct.
In court on Tuesday, Sun's attorney argued that the mayor has simply been trying to clean up the city and has done nothing wrong.
Judge Laura Inveen rejected most of the arguments made by those pushing for a recall, but said Sun's alleged actions that may cause the city to lost its liability insurance do "justify a finding of factual and legal sufficiency that the mayor violated his oath of office."
She ordered both sides to work on new ballot language for the potential recall.
Sun has 15 days to appeal Inveen's ruling. Barring a successful appeal from Sun, residents will then need to gather enough signatures to put the recall to a vote.