In his ruling on the ban, the judge said Uber drivers lacked the necessary authorization to drive vehicles and acted as unfair competition to the existing taxi industry.
The move comes after legal action was taken against the California-based company by the Madrid Taxi Association.
The judge said his ruling was not a philosophical statement on the free market or the sharing economy but was a precautionary measure based on existing Spanish law.
The position of Uber was not heard in court as the company is domiciled in the US state of Delaware for tax purposes.
"This is a highly unusual judicial ruling on commercial matters," Uber said in a statement provided to The Local by email.
"This decision is incompatible with the general political recognition in Spain and in the European Union of the benefits of sharing resources and the sharing economy in a moment of high unemployment and fragile economic growth," the company said.
"Uber will continue to comply with Spanish legislation and is currently looking at an appeal against these sudden and unusual proceedings."
The ban is the latest salvo in the battle against Uber in Spain. Both Madrid and Barcelona have previously announced financial sanctions against Uber drivers, while Catalonia recently said it was considering impounding vehicles with drivers having to pay €6,000 ($7,500) to have their cars released.
The Spain ban also comes a day after the taxi-booking app was banned in Dehli because of the alleged rape of a passenger by an Uber driver.