The 62-year-old, who is also a vice president of UEFA and FIFA, was the only candidate for the post at a general assembly at the RFEF headquarters outside Madrid and received 161 of 167 votes, with five blank votes and one void.
A Spanish court had earlier rejected a last-minute bid to have the election postponed filed by Ignacio del Rio, a former Madrid city councilor who has accused Villar and the RFEF of violating electoral rules by bringing the vote forward in what Del Rio said was a "murky atmosphere."
The court, the Audiencia Nacional, ruled that the case was not of "special urgency," as Del Rio argued, and that allowing the election to proceed on Thursday was unlikely to "damage the public interest."
A triumphant Villar, with UEFA President Michel Platini watching from the front row, thanked delegates including Spain coach Vicente del Bosque for their support and said the election was "an example" to other federations around the world.
"It's legal and it's absolutely democratic," he said, noting that regional federations and coaches and players from all over Spain and from every level of soccer had taken part.
The former Athletic Bilbao and Spain player, who is seen as a possible future president of UEFA or FIFA, did not address the allegations directly.
Platini made a brief speech in Spanish in which he said he was "proud and happy" to be present at the election and that the global football community needed people like Villar.
Del Rio, who has said he would have stood against Villar given the chance, was quoted as saying in local media on Thursday that there had been "a violation of the rules and a degree of secrecy" in the electoral process.
"The rules are there to guarantee fairness and transparency, but in this case the elections have been arranged in a murky atmosphere," he added.
"Something must be wrong when the elections are called under these conditions. They must be trying to hide something. If not, this is not a reasonable way to behave."
Manos Limpias (Clean Hands), an organisation dedicated to fighting corruption, filed a complaint against the election in a Madrid court on Wednesday alleging Villar had conspired with a former government official to "rig" the vote.
"A clean electoral process requires the scrupulous application of the rules of the democratic process and respect for the law and the rule of law," the organisation said on their website.
The professional football league (LFP) and the national coaches' association (ANEF) had also expressed concern about the election, sports daily Marca and other media reported.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.