Alves, regarded by many as the most successful player in history, had rejoined Barca in November but confirmed last month that he would not be extending his contract.
The international star signed before the cameras after a medical that Pumas president Leopoldo Silva said had gone “very well”.
Alves said that he wanted to “leave a legacy for younger people so that they can keep fighting for what they dream of, because here is living proof that everything in this life is possible”.
“I come from a small town where people want to win,” he added, explaining his decision to join the Pumas, who are linked to the National Autonomous University of Mexico (UNAM).
“Soccer has transformed my life and I want it to continue transforming the lives of many people, and that’s why I accepted the challenge of coming to the Pumas,” he said.
Alves joins Argentine attackers Gustavo del Prete and Eduardo Salvio who have also signed with the seven-time Liga MX champions.
Alves made 408 appearances in total for Barcelona, with 391 of those coming in his first spell from 2008-2016.
During that initial stint, he won six La Liga titles, three Champions League crowns and four Copa del Rey trophies.