Manager Bruce Bochy said Longoria is expected to be sidelined for at least a couple of games, but he said he does not consider the injury to be serious.
The 32-year-old Longoria will be replaced in the lineup by Pablo Sandoval, who will play third and bat fifth.
Longoria, who has been dealing with swelling and inflammation of his left ankle joint since spring training, tweaked the ankle while taking some pitches during a pregame bullpen session for Giants pitcher Derek Holland, Bochy said.
"That's all he was doing, but somehow he just tweaked it," Bochy said. "I don't know how."
Despite the nagging injury, Longoria has appeared in 14 of 15 games this season. He leads the team in doubles (five) but is hitting only .204 with two home runs and five RBIs in his first season since he was acquired from Tampa Bay in December.