Nations and environmental groups have agreed to shut down the domestic ivory trade, despite the resolution nearly being derailed by objections from countries including Japan and South Africa.