The deal was agreed in principle some time ago and has finally been confirmed.
Boro and Real Madrid were unable to complete formalities until the international transfer window opened at the start of this month.
Mejias, who made just one appearance while on loan from the European Champions before breaking and dislocating a finger last season, has signed a two-year contract.
"It is great to have everything sorted out," said a delighted goalkeeper this morning.
"I know it is a big move from Real Madrid, but it is one I had to make and I'm very happy to have made it. I enjoyed myself here last season."
Mejias knows he faces competition for the number one jersey at the Riverside.
"It was the same last season, before I was injured. 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.
"All I know is I am delighted to be here and to be given a chance."