The non-binding recommendation urges countries to set up AIDS prevention programs in places of employment and help infected workers be productive for as long as possible.
Government officials, employers' groups and trade unions approved the recommendation by a large majority at the ILO's annual ministerial conference, after two years of discussion.
The agreement also covers armed forces and uniformed services, the ILO said in a statement.
"With the recommendation we can ensure confidence of job security and access to treatment," said Sophia Kisting, director of the ILO's program on HIV and AIDS and the world of work.
"We want to get rid of the silence and the shame around it and let people know they won't lose their job or won't be shunned at work," she told reporters.
It will be up to the U.N. agency's 183 member states to decide how to integrate its principles into their national policies and legislation.
The United Nations estimates 33 million people around the world are infected with the virus that causes AIDS and says more people are living longer thanks to the availability of drugs.
The recommendation is less powerful than an ILO convention requiring ratification, but aims to harmonize programs.
"To this day, stigma and discrimination still means job losses, it still means a lack of access to jobs and it still means that through fear and going too late for an HIV test that potentially a life is lost," Kisting said.
Employers should accommodate infected workers and train them to acquire new skills, she said.
"Psychological support from fellow workers when you are ill ... is so important to boost the will to live," she added.