Mayor Josu Bergara was recorded in a meeting last year boasting that he had made sure "the scum no longer come" to his northern town of Sestao.
Five Romanian families lodged a complaint against him in court, accusing him of illegally refusing to register them as residents in the Basque town.
They submitted a video of his outburst as evidence of racism to support their case, said the campaign group SOS Racismo, which aided the families.
"The scum no longer come to Sestao. I make sure they leave, by thumping them," he was recorded saying at a meeting in June 2013.
Bergara apologised on Thursday after the video was broadcast by media covering the court case.
He said he had been referring to "delinquents" in general, not Romanians in particular as the plaintiffs alleged.
"I acknowledge that the comments that have come to light were inappropriate. We want Sestao to be a multicultural, hard-working and civil place," he said.
But he added: "We cannot allow people to come here to rob. In the video I was referring to delinquents and antisocial people."
SOS Racismo said it was "unacceptable that his comments be played down, even if the apology is sincere".
Romanians are the biggest foreign nationality group in Spain. They numbered about 795,000 in 2013, according to the National Statistics Institute.
Bergara's apology is the latest in a spate of recent racism-related incidents in Spain.
In the most high-profile of those, a fan with Spanish football club Villarreal made international headlines when he threw a banana at FC Barcelona Dani Alves.
Alves decided to eat the banana, a reaction which quickly turned into a worldwide anti-racism campaign with the help of his Brazilian teammate Neymar.