Christian Castillo had given El Salvador a 1-0 lead in the 32nd minute with a header over USA goalkeeper Tim Howard. But Dempsey equalised in the 41st minute when he headed in a free-kick from Landon Donovan. Donovan's cross in first-half injury time also supplied Altidore.
Howard's save off William Reyes's point-blank shot in the 87th preserved the victory in the final round of qualifying in the North, Central America and Caribbean region.
"I think what stood out after the goal (was conceded) was the strong response from everybody on the field," said USA coach Bob Bradley. "That says a lot about what these guys are all about. They understand how difficult these games are and how competitive they are.
"El Salvador is very well coached and they play hard every game. Their three previous results in away games were all 1-0 losses, so nobody has an easy game against them."
Three teams advance from the region directly to next year's finals in South Africa. The fourth-placed team will play-off for a berth against South America's fifth-placed team.
The victory enabled USA to improve to 13 points with three games remaining, starting on Wednesday at Trinidad and Tobago.