Gracia initially signed an 18-month contract when he was hired to replace the sacked Marco Silva in January, which was due to expire at the end of this season.
A contract until 2022 is a significant show of faith in the Spaniard from a club that has hired and fired three other managers since earning promotion to the Premier League in 2015.
"I am very happy to extend my contract. I am very proud in this moment to be part of this club and to belong here for more seasons," Gracia told the Hornets' official website.
"We are delighted that Javi has agreed an extension to his contract, chairman and CEO Scott Duxbury, commented.
"From day one it was clear that Javi worked well with us and shared our vision of how to achieve success for Watford Football Club, and we are looking forward to continuing that work together for many years to come."
Watford have enjoyed a good start to the Premier League season and were one of the last teams left with a 100% winning record after emerging victorious in each of their first four games.