The 20-year-old attracted interest from Newcastle boss Alan Pardew after scoring 16 goals in 34 appearances for the Spanish second tier side.
Perez started his career at Tenerife, progressing through the youth ranks, but is relishing his new challenge at St James' Park.
"I'm very happy to be here to start this new adventure," he told the club's official website.
"I'm very eager for it to begin and I'm very pleased to play for this magnificent club.
"Any football player would be interested in playing for such a club and I will earn my position to get in the first team."
And Pardew added: "We're delighted to confirm our first signing of the summer and very pleased to have Ayoze at Newcastle United, as a number of other clubs were chasing his signature too.
"He had a terrific season in Spain last year and is a player who we hope to develop further on Tyneside.
"He's only 20 but has a very good eye for goal and that's a great asset for any young player to have."