The law, punishable by an unlimited sentence, will apply retroactively against any person who sets foot on Swedish soil, wherever their victims may have been.
"Crimes include, for example, homicides, sexual violence and torture, when they are committed within the scope of a widespread or systematic attack directed against a civilian group," the parliament said in a statement.
The crime of arranging a forced marriage, punishable by up to four years in jail, was also adopted without a vote on Tuesday.
The Swedish government announced its plan to write the offence into law in January on the twelfth anniversary of the murder of Fadime Sahindal, a 26-year-old from Turkey killed by her father when she refused an arranged marriage.
The offence consists of "exploiting someone's vulnerability to force them to marry," including by exerting pressure on a young person, or suddenly sending them abroad to be wed.
War crimes had previously been included in Sweden's penal code, which had been used to prosecute for crimes committed in the former Yugoslavia and the Rwandan genocide.