The former Valencia and Barcelona striker departs Atletico Madrid after just one season, having scored 13 league goals to help his side become Liga champions for the first time since 1996.
The forward will begin playing for New York City at the start of the 2015 MLS season, which will begin in March of that year, and will be the club's inaugural campaign in the competition.
“Throughout my career I've always tried to keep pushing myself to achieve new targets and this represents another important goal for me,” the 32-year-old told New York City's official website.
“I want to try and help MLS continue to grow, through playing, working hard, scoring goals and at the same time try to make New York City FC become the best team in the league.
"It's a real honor that the people who have formed the club have focused their attention on me.
"I'm keen to do the best I can, take on board that extra responsibility and prove my worth by repaying the confidence they have shown in me,” he added.
Meanwhile, City's CEO called the signing a historic event for the club.
“This is a historic and exciting moment for the City family and the building of New York City Football Club,” said Ferran Soriano.
“I know David really well; he is one of the best footballers in the world, a true winner and in an outstanding moment of his career. I’m sure New Yorkers will enjoy watching him play for their city,” he added.
Villa has won 94 caps for Spain, scoring 56 goals and was named in their 23-man squad for this summer's World Cup in Brazil.