But the Portugal international insisted the act, which was missed at the time by the referee, was "unintentional".
The 28-year-old was branded "shameful" and "embarrassing" in the Spanish press following the incident during the Copa del Rey quarter-final first leg at the Bernabeu, which came when Messi was lying on the ground.
And in a statement on the club's website, Pepe said: "I wish to say yesterday's incident with Leo Messi was unintentional, but I nevertheless want to apologise to him if he was offended because all I do is defend my team and this institution.
"I give my heart and soul, and the thought of hurting a colleague has never entered my mind."
The usually pro-Madrid newspaper Marca pulled few punches in its reaction to the incident.
After the match, coach Jose Mourinho said Pepe had played well for the team, but warned he would be punished if it was found he had deliberately stamped on Messi.
"I haven't seen it, but obviously if it is deliberate he will be punished," Mourinho said.
"What I can say is that he did a great job for the team."
But Marca went further, suggesting Pepe's long disciplinary record calls into question whether he should remain at the club.
Pepe received a 10-match ban during the 2008-09 season for kicking Getafe's Francisco Casquero while he was on the ground.
Miguel Serrano wrote in the paper: "Real Madrid itself should act on its own and punish Pepe. And then, in time, study his future at the club. If he has one."
On marca.com, Roberto Palomar wrote on his blog: "Real Madrid, in the form of (president) Florentino Perez, should consider very seriously getting rid of a player who is an embarrassment for Real Madrid, who lives up to neither the club's history, nor the stature of his colleagues or the profession of football.
"The winter transfer window would be a good opportunity to get some money for him and avoid him every wearing the white shirt again. If there is any bit of sense at the club, this should have been his last match."