The 28-year-old Brazil-born Spain international joined the Blues from Atletico in July 2014, scoring 59 goals in 120 appearances.
Costa won two Premier League titles in his three seasons at Stamford Bridge, but admitted to pandering for a return to Atletico as early as his first season in England.
And after months of acrimony, claim, and counter-claim, Costa has been granted his wish after the Blues and Atletico agreed a fee reported to be in the region of £58 million (€65 million).
Chelsea play at Atletico next Wednesday in Champions League Group C and all parties will be relieved the matter has been resolved.
A Chelsea statement read: “Chelsea Football Club has today agreed terms with Atletico Madrid for the transfer of Diego Costa.
“The transfer will be subject to the agreement of personal terms and a medical.”
Costa will now travel to Madrid from Brazil to finalise his move.
Atletico said: “Atletico de Madrid and Chelsea have reached an initial agreement for the transfer of Diego Costa.
“The agreement is pending the formalisation of the contract between our club and the Spanish international forward.
“The English club has authorised Diego Costa to travel to Madrid in the coming days to undergo medical tests and settle his contract with our club.”
With Atletico under a transfer embargo and unable to register new players until January, Costa will have to wait to wear the red and white stripes once again.
Costa last season submitted three transfer requests, one prior to the start of the campaign which ended with his second Premier League winners’ medal, as his exit became fractious.
Costa’s last game for Chelsea was May’s FA Cup final loss to Arsenal, when he scored the last of his 59 goals.
Relations with the Blues and head coach Antonio Conte were damaged in January when Costa reportedly had his head turned by a big money offer from the Chinese Super League, which soon evaporated.
Costa’s availability had alerted numerous clubs, but he only wanted to go to Atletico to be reunited with their head coach Diego Simeone and now he has his wish.
Costa may yet join another team on loan before Atletico can register him in January or he may opt to work on his fitness in Madrid following his extended summer break.
Meanwhile Chelsea midfielder Tiemoue Bakayoko was involved in a minor car accident on his way home from training yesterday. The France midfielder was not injured and is expected to be in the squad tomorrow at Stoke.