Earlier, Spain's Prime Minister Pedro Sanchez had said his country would be willing to host the game.
The match was called off last Saturday when visiting Boca's bus was attacked while on its way to Argentine rival River's stadium, and several players were injured.
Fearing more violence, organizers decided earlier this week the game should be played in another country.
"In Spain we find the necessary tranquility... Madrid is the 10th safest city in the world and it has the largest Argentine community in Europe," CONMEBOL president Alejandro Dominguez said on Thursday. "I don't think the essence of the Libertadores will be lost because the game will be played in Spain."
Dominguez added the game would be staged at Real Madrid's Bernabeu stadium at 8:30 pm Spanish time, and that Boca and River fans would be allowed in.
South American soccer's governing body rejected a request by Boca to be declared winners, but has fined River $400,000 and ordered the club to play the next two CONMEBOL games behind closed doors.
The first leg ended in a 2-2 draw.