KABUL—Two Western hostages, one American and one Australian, were freed by the Taliban after more than three years in captivity in a prisoner exchange that could spur resumption of negotiations to end the 18-year Afghan war.

In return for Tuesday’s release of the American, Kevin King, and the Australian, Timothy Weeks, the Afghan government freed three high-profile Taliban members belonging to its most feared faction, the Haqqani network. They include Anas Haqqani, the younger brother of the Taliban’s deputy leader and top...