Gila's departure follows the exits of Alessio Romagnoli, joining Inter Milan, and Ivan Provedel, heading to Al Sadd.
Lazio had publicly insisted they were prepared to let the Spaniard run down his contract, but were in reality waiting for the right offer.
Napoli were linked but moved too slowly, while an offer of around €25 million including bonuses from Atalanta was turned down by Gila himself.
AC Milan are now positioned to complete the signing, with talks set to be finalised early next week.
The club has already reached full agreement with the player on a five-year contract worth more than €4 million net per season, rising to around €5 million with bonuses.
Lazio are expected to push for a fee above €25 million including bonuses when the two clubs meet on Monday, though they may settle for the roughly €22 million plus €3 million in easily achievable bonuses already effectively agreed with Atalanta.
Lazio will not receive the full amount, however, as Real Madrid are entitled to 50% of any profit on a future sale of the player.
Lazio paid €6 million for Gila in the summer of 2022, meaning Real Madrid's share would be calculated on the remaining €16 million if Milan's €22 million fixed fee is confirmed.
That would leave Real Madrid with around €8 million and Lazio with the remaining €14 million of the fixed fee.
Combined with incoming fees for Provedel and Romagnoli, Lazio's departures would generate around €20 million, which the club needs to fund further transfer activity after a third summer in four years of restricted spending.
