MADRID, May 23 (Reuters) - Villarreal have agreed to sign Barcelona's Brazilian midfielder Edmilson on a two-year contract. The versatile 31-year-old, who helped Brazil win the 2002 World Cup in Japan and South Korea, started his career with Sao Paulo and Olympique Lyon before moving to Barcelona in 2004. He helped Barca win the Champions League two years ago but withdrew from his country's 2006 World Cup squad with a knee injury. He only made five starts for the side last season and his contract expires in June. Villarreal were runners up to Real Madrid in the Primera Liga earlier this month, finishing ahead of third-placed Barca, to earn automatic qualification to the Champions League for next year. In his farewell news conference in Barcelona, Edmilson said the last two years when the club failed to win any silverware, had been the hardest of his eight years in Europe. 'We thought that because we had the best team we would win everything, but at the end of the day the other teams have been much better prepared than us,' he told a news conference. 'When you don't win it is normal to make changes, and to refresh the mentality in the squad.'