The 37-year-old played for the Yellow Submarine during a spell when they finished third in La Liga and reached the semi-finals of the Champions League where they were knocked out by Arsenal on penalties.
Bees sporting director Mark Warburton expressed his delight at the arrival, telling the club's official website: "This is a signing that brings a wealth of experience and ability to the squad. He has an outstanding reputation in Spain for his professionalism and approach to the game.
"Javi has, like all our signings, been put through a rigorous testing procedure and we are delighted to see how well he performed and how clear his ambition is to take on a new challenge of the like presented by Brentford.
"This is a very different signing and is a coup for us. We are looking to expand our recruitment network and add value to the squad.
"We hope this signing sends out a message to the fans. We are looking forward to welcoming him to Griffin Park."