The United States scored at beginning and the end, but for most the match it was on the back foot as the Africans attacked, pushed the Americans deep into the box, but failed to finish in a physical match.
Dempsey's goal was the quickest ever by an American and one of the fastest in World Cup history. He's the first American to score in three different World Cups.
Brooks got the winner on a header in the 86th, just four minutes after Andre Ayew equalized.
The 21-year-old defender was a second-half substitute and an unexpected addition to the American roster. He was overcome and fell to the ground as teammates piled on. He made his national team debut in August.
"I said it to the bench minutes before, we're going to get some chances still," U.S. coach Jurgen Klinsmann said. "So we are still in the game after the equalizer, we just need to kind of push and push and grind it out. That's what they did."
U.S. players ran onto the field to celebrate at the final whistle, jumping as supporters chanted "U-S-A! U-S-A!"
"We have a great spirit," Klinsmann said. "The U.S. team always has a great spirit and fights until the last second."
The defending Cup of Africa Nations champion, Nigeria will be more disappointed with the draw than Iran.
Neither Iran nor Nigeria has won a match at the World Cup since 1998.
Stephen Wade on Twitter: http://twitter.com/StephenWadeAP