President Obama on Wednesday endorsed gay marriage, becoming the first U.S. president to voice support for same sex-couples to legally marry.

Obama said he had concluded “personally” that same-sex couples should be able to get married. He said he came to the conclusion after years of conversations with friends, family and neighbors, as well as with members of his staff who are in same-sex relationships.

The announcement is a landmark for the gay rights movement, which has battled for decades to win legal recognition for same-sex marriages.

But the sudden shift by Obama in an election year on the explosive issue could pose a risk to the campaign by alienating socially conservative, independent voters who do not support same-sex marriage.