Pepe played for Porto between 2004 and 2007 before being snapped up by Real Madrid, whom he represented for a decade.
The most successful days of his career were at the Santiago Bernabeu, winning both the UEFA Champions League and LaLiga three times.
He joined Besiktas in 2017 and was well-regarded by supporters, but he opted to agree to a mutual termination of his contract towards the end of last year in a bid to help the club's worsening financial woes.
Reports swiftly suggested a return to Porto was on the cards, and the deal was finally announced on Tuesday.
He re-joins the club seven points clear at the top of the league table and could make his second debut in Saturday's important trip to Sporting CP.