After a board meeting at Valencia in the morning, their president Manuel Llorente said they had accepted Barca's offer for the striker who scored 21 league goals last season to finish his fifth consecutive campaign as the club's top scorer.
"We have sold David Villa to Barcelona for 40 million euros," he told a news conference at the Mestalla.
On the international stage, Villa is Spain's second highest scorer with 36 goals from 55 matches, eight short of Raul's record, and he will be spearheading Spain's World Cup campaign in South Africa next month.
Barcelona confirmed the deal in a statement on their website saying the 28-year-old would sign a four-year contract with an option for one more year.
The player, who Barca said 'guaranteed goals', will travel to Barcelona on Thursday and will take a medical before being presented on Friday.
At Barcelona he will join a formidable forward line that already includes La Liga's leading marksman Lionel Messi, Zlatan Ibrahimovic, Pedro and Bojan Krkic.
France striker Thierry Henry spent most of last season on the bench and is expected to move on.
Valencia have been forced into the sale by the precarious nature of their finances. They are burdened with debts of around 500 million euros ($620.8 million), they have a half-built new stadium, and have yet to sell their current one, the Mestalla.
"The board's principle objective is to make sure we have economic viability for the future," Llorente added. "We are obliged to take responsible decisions. Considering our situation it is responsible to sell this player.
"As everyone knows we could have done this deal last year but we thought at that moment it was best to keep our squad together to try and get into the Champions League.
"We have achieved that aim and finished third in the league, and he has contributed a lot towards this. We think it is good sale and necessary for the economic situation of the club."