The non-binding proposal was approved at a meeting of the Convention on International Trade in Endangered Species (Cites) in South Africa.
Conservationists hailed it as a significant step towards ending the current elephant poaching crisis.
However Japan, which has a large domestic ivory trade, said the proposal did not apply there.
While the international market in ivory has been closed since 1989, legal domestic markets have continued in many countries around the world.
There has been growing concern that domestic trading has encouraged the poaching of elephants.
A surge in killing over the past seven years has seen populations across Africa shrink by a third, according to the recently published Great Elephant Census. What is driving the slaughter is the value of ivory, which can sell for around $1,100 (£850) per kilo in China.
Countries including the US and China have announced plans to close their markets. The UK recently did the same, banning all trade in ivory dated from 1947 until the present day.
Trade in materials from before 1947 will continue.
While the nations attending this conference are divided on the best approach to protecting elephants, a compromise on the issue of closing domestic markets was arrived at after some heated discussions in a working group. However the measure then passed by consensus.
The agreed text calls is not legally binding and Cites can't compel countries to follow, but conservationists believe that it is a strong move as it is the first time that the 183 countries that have signed the Convention have taken a unified position on this question.
"It's an important step on the road to closing worldwide ivory markets. It's the first time that Cites has agreed to intervene so directly in domestic ivory," said Robert Hepworth, a former chair of the Cites standing committee.
Because it is a compromise, the new resolution does come with a significant caveat. It encourages countries to close their markets where those markets are "contributing to poaching or illegal trade".
Some countries, including Japan are likely to argue that their markets don't contribute to poaching so they don't need to close them.
Speaking to the Japanese press, the country's environment minister expressed the view that the resolution wouldn't apply to Japan as there was no poached ivory in their market. Campaigners disagree vehemently.
"There is evidence that has shown that Japan's market has illegal ivory, fraudulent documents are used and there is ivory from illegal or unknown origins circulating in the market," said Iris Ho, from Humane Society International.
"It's very disappointing for the Japanese government to deny the existence of illegal ivory in their markets - Any legal market serves as a very convenient cover for illegal ivory to be laundered."
What surprised many of the participants who drew up the resolution was the position taken by China, one of the biggest markets for illegal ivory.
According to those involved, the Chinese were looking for an even stronger text on market closure.
"China wanted a very clear message that all domestic, legal markets should be closed," said Patrick Omondi who is part of the Kenyan delegation at Cites.
"The fact that they have recognised there's a problem with their domestic market and are working to close that market, is a very good signal for the conservation of the African elephant."
The unity displayed on the closure of markets may well be short-lived. Monday will see differing proposals on the future of elephants. Namibia and Zimbabwe are seeking to have elephants in their countries downgraded, paving the way for legitimate exports of ivory.
A coalition of other African countries is proposing the very opposite. They want to upgrade all African elephants to the most protected status, removing any possibility of a commercial trade.
There is very likely to be a heated debate, and the feeling among observers is that neither proposal will command the two-thirds majority needed to alter the Convention.
Follow Matt on Twitter @mattmcgrathBBC and on Facebook.
Delegates at a UN wildlife conference have endorsed calls for the closure of all domestic ivory markets.