Iran won their first match at a World Cup finals since 1998 as Morocco substitute Aziz Bouhaddouz scored an own goal in injury time.