Costa was a free agent after leaving Wolverhampton Wanderers at the end of last season.
The 34-year-old scored just one goal in 25 Premier League appearances during his one-season stay at Molineux.
Botafogo turned to Costa after losing leading striker Tiquinho Soares to a serious knee injury.
Botafogo are currently managed by former Wolves boss Bruno Lage.
A club statement read: 'Botafogo continues to build a quality squad and will count on the experience of Diego Costa, a 34-year-old striker, on a contract signed until the end of 2023.'
'Diego will arrive in Rio de Janeiro in the coming days and will be reunited with coach Bruno Lage, with whom he worked at Wolverhampton in England.'
'I'm very happy to have been chosen to be part of the family. Thanks and I see you soon,' Costa said in a social media post.
Costa also previously spent three seasons in the Premier League with Chelsea, scoring 52 goals in 89 top flight appearances.
He won two titles with the Stamford Bridge outfit before a falling out with then-Chelsea boss Antonio Conte in 2017 led to his departure to Atletico Madrid.
Costa was born in Brazil but has represented Spain at international level, winning 24 caps for La Roja and scoring ten goals.