"When I was a kid, I wanted to play for Barca, it was a dream. We all know that it is the best place to play football and when I heard about their interest I didn’t think twice," he said.
The 24-year-old midfielder, who came through the ranks at PSV Eindhoven and whose family are from Morocco, has 29 caps for his country and was a member of the squad which reached the World Cup final.
Barcelona paid PSV three million euros (3.9 million dollars) for Afellay and his contract includes a buyout clause worth 100 million euros, the club said in a statement posted on its website.
The club's sporting director, Andoni Zubizarreta, praised Afellay's versatility and maturity and said he would be the only player bought during the January transfer window.
"We have absolutely no plans to sign anybody else," he said during the player's presentation.
"He was a player who was about to finish his contract and with the squad we have he looks like somebody who can add something."