Pepe, 35, was made a free agent in December after rescinding his contract by mutual agreement with Besiktas.
But the Brazil-born ex-Portugal international will not spend long on the market, with a move back to Porto imminent.
Talks with the Dragao began at the end of December following his release from Turkey, with a deal expected to be signed this week.
Pepe is expected to put pen to paper on a contract that is set to run until June 2020, by which time the defender will have turned 38.
Porto were not the only side interested in the player's services.
Wolves were reportedly following Pepe's movements, as were Al Gharafa of Qatar and Saudi Arabia's Al Ittihad.
Ultimately, however, the centre-back opted to move back to Portugal due to his family's wishes, which proved key in his negotiations with Porto.
Dragao fans remember Pepe fondly from his previous spell at the club, which ended in 2007 when he moved to Madrid.
Pepe spent a total of three seasons in Porto, making a total of 88 appearances in all competitions.
The centre-back helped his club to back-to-back Primeira Liga titles in 2005-6 and 2006-7, as well the 2004 Intercontinental Cup after defeating Once Caldas in Yokohama.
He then went on to star at the Bernabeu for a decade, lifting three Liga crowns and three Champions Leagues as he formed a formidable defensive partnership alongside Sergio Ramos.