AS and the club will make the final payment of €2.7 million on Monday, with the final bill to be announced by the Spanish club on Tuesday.
The agreement will take effect on January 1, 2018.
Real Madrid will pay €1.6 million to AS and €2 million in player bonuses.
The move will take AS to fifth place in La Liga, one point behind second-placed Real Madrid.
AS will also earn €7.5 million from the sale of the Copal, as well as €2 in cash from AS’ TV rights.
Real will pay AS a profit of €4 million in 2018-19.
The signing of the two Spanish players, who signed from Sevilla for a total of €1 million in 2013, will help AS recover some of the €10 million it lost in its attempt to buy the club in 2015.
Real Madrid is one of the world’s biggest clubs and the Spanish champions have been linked with a number of top European clubs in recent years, including Real Madrid and Juventus.
AS has already had success in the Copas del Rey.
Real beat Barcelona 2-1 on penalty kicks to win the title in 2014.
Real have won three Copas de Madrid titles in a row.
Despite the success, AS is still struggling financially.
In 2019, the club said it would have to sell its Copa Mundial and the 2019/20 Champions League for €10.5 billion euros ($13.1 billion).