The clashes started as fans arrived at the Santiago Bernabeu stadium in the Spanish capital on Tuesday evening
Among them is the leader of an ultra group, a police spokeswoman said, without giving further details.
The clashes started as fans arrived at the Santiago Bernabeu stadium in the Spanish capital on Tuesday evening before kick-off for the Group F game, which Real Madrid won 5-1.
Some fans hurled objects, including glass bottles and flares, at police, threatening journalists who recorded the skirmishes which lasted half an hour before order was restored.
Five Polish fans and two police officers were treated for minor injuries in the clashes.
The 13 detainees are accused of robbery with violence and intimidation, inflicting damages and injuries, and public disorder.
Among them are three people suspected of having attacked waitresses in a bar in the Latina district of Madrid hours before kick-off, stealing the mobile phone of one woman and attempting to rob cash from the till, police said.
The game had been classed as a high-risk fixture by the Spanish authorities, who deployed 2,000 officers in Madrid.
UEFA has already ordered the return match between the sides in two weeks' time be played behind closed doors due to violence and racist abuse in Legia's opening 6-0 defeat in Group F to Borussia Dortmund last month.