Mr Obama said the measure would send a strong message that Washington was paying attention to the way governments elsewhere in the world treat the media.
The law is named after US journalist Daniel Pearl, who was beheaded by militants in Pakistan in 2002.
He was working on a Wall Street Journal story about radical Islamist groups.
Mr Obama was joined for the signing ceremony by Pearl’s widow, Mariane, the couple’s seven-year-old son, Adam, and the journalist’s parents.
He said the law—named the Daniel Pearl Freedom of the Press Act—would show countries that repressed freedom of speech that they could not operate against the media with impunity.
“The loss of Daniel Pearl was one of those moments that captured the world’s imagination because it reminded us how valuable a free press is,” Mr Obama said.
“This legislation, in a very modest way, puts us clearly on the side of journalistic freedom.”
In the above report, Daniel’s parents and wife are standing behind Obama. You can’t see them in the video, but the photo accompanying the Jewish Journal story shows Ruth Pearl directly behind Obama, with Judea on her right and Marianne to his right.