The 30-year-old, capped 25 times by Scotland, joins Bruce Arena's side as a free agent, subject to receiving his International Transfer Certificate and P-1 Visa.
Gunn will occupy an International Roster Slot returning to San Jose from LA Galaxy when the Secondary Transfer Window opens on July 13.
“It feels incredible to join the Earthquakes,” said Gunn.
“Coming off the World Cup which was an unbelievable experience, I’m just really excited and grateful for the opportunity to come to San Jose and show the best version of myself.
“We’re in a really good position for the playoffs, so hopefully we can focus on that with the right mentality.”
The Earthquakes currently sit second in the Western Conference and third overall, with Gunn aiming to help the club mount an MLS title challenge.
