Pepe's contract with Porto would have expired at the end of this season but he has decided to prolong his career by one more year.
Pepe is in his second spell at Porto, having spent a decade at Real Madrid and two seasons with Besiktas in Turkey.
"I'm very nervous because it's a contract that means a lot to me," Pepe, who has played 28 times this season, told Porto's official website.
"As a player and person, I usually say I'm very honest. I'm 40 years old but I owe a lot to Porto and I don't want to defraud the president or the people at the club.
"I want to thank everyone at the club for making me better every day as a player, a person and a father."
Pepe has won four Primeira Liga titles in his two spells with Porto.
He also won three Champions League trophies and three La Liga titles during his time at Real Madrid.
Porto are four points adrift leaders Benfica in the race for the league title with five games to go.
Pepe has won 133 caps for the Portugal national team and is yet to retire from international football.