Mejias made just one appearance on loan at the Riverside Stadium during the second half of the season, but the Spaniard has insisted that he is happy to fight for his place on his return to the North-East.
The 25-year-old told the club's official website: "It is great to have everything sorted out.
"I know that it is a big move from Real Madrid, but it is one that I had to make and I'm very happy to have made it. I enjoyed myself here last season.
"I am competing with two very good goalkeepers in Dimi and Steeley. Nothing has changed, and we are all in a fight for the spot, we all know that."
Mejias links up again with head coach Aitor Karanka, who was part of the backroom staff at the Bernabeu before being appointed as Middlesbrough head coach in November.