It is the last of a package of ten laws that had to be approved for the European Union to consider visa-free travel for Ukrainians.
Several previous attempts to get the bill through parliament failed over fears it would lead to the introduction of same-sex marriage in Ukraine.
The decision was supported by 234 MPs.
The speaker of parliament assured deputies that the law would not threaten "family values", saying: "I hear some fake information which says that there may be same-sex marriages in Ukraine. God forbid, this will ever happen. We will never support this."
In response to the vote, Ukrainian president Petro Poroshenko tweeted: "Ukraine is breaking free from the shackles of discrimination from the Soviet past. Meanwhile, family values remain inviolable."
EU officials will meet in two weeks to decide whether the conditions for extending visa-free status to Ukrainian nationals have been met.
Ukraine's parliament has passed a law banning discrimination in the workplace, including that based on sexual orientation.