The board of the Metropolitan Transportation Authority voted on Wednesday to ban political advertising on New York City subways and buses to avoid the legal challenges it had faced after rejecting some ads with political messages.

The vote followed a lively debate over free speech as dissenting board members and advocacy groups argued that the transit system was a public space that should be a forum for debating political issues. The new policy, which took effect immediately, prohibits ads for political parties or ballot referendums or any ad that is “political in nature.”

The authority still allows commercial advertising, paid messages by the government and some public service announcements. Officials at the agency said the legal challenges over contentious ads had become a distraction.

The change came a week after a federal judge ordered the authority to display an ad produced by a pro-Israel group that the authority argued could be interpreted as a call to violence. The agency had lost an earlier lawsuit in 2012 over another ad by the group, the American Freedom Defense Initiative.