President Barack Obama came out in favor of legalizing same-sex marriage for the first time in an ABC News interview on Wednesday.

I've just concluded that for me personally it is important to go ahead and affirm that I think same-sex couples should be able to get married, Obama told Good Morning America's Robin Roberts, according to clips and transcripts released ahead of the interview to be aired in the evening. He is the first president to take that position while serving in office.

Obama said his position was a personal one and he still believes that states should be able to decide on the issue on their own.

Obama's endorsement of same-sex marriage comes after a week of speculation that was triggered by comment made by Vice President Joe Biden on Meet the Press Sunday morning, in which he said he was comfortable about the idea of same-sex couples marrying. Until the ABC interview, Obama and his press secretary Jay Carney dodged questions about the issue.

Some political commentators, like the New York Times' Frank Bruni, thought that Biden's comments were a way for Obama to test the waters if he were to make a statement on the issue.

For years, Obama has gone back and forth on how he feels about legalizing same-sex marriage. In 1996, running for the Illinois state Senate in a liberal Chicago district, he said he was in favor of legalizing it, but flipped his stance when he ran for the U.S. Senate in 2004. Most recently he said his stance was evolving but came short of fully endorsing it.

Obama described his thought process to Roberts on Wednesday, explaining that acceptance of same-sex couples has come with the times.

It's interesting, some of this is also generational, the president said. You know when I go to college campuses, sometimes I talk to college Republicans who think that I have terrible policies on the economy, on foreign policy, but are very clear that when it comes to same-sex equality or, you know, sexual orientation that they believe in equality. They are much more comfortable with it. You know, Malia and Sasha, they have friends whose parents are same-sex couples. There have been times where Michelle and I have been sitting around the dinner table and we're talking about their friends and their parents and Malia and Sasha, it wouldn't dawn on them that somehow their friends' parents would be treated differently. It doesn't make sense to them and frankly, that's the kind of thing that prompts a change in perspective. 

Excerpts of the interview will air Wednesday night on ABC's World News with Diane Sawyer.