President Obama named OUT magazine's 'Ally of the Year.' (Courtesy of OUT magazine)

Celebrating a year in which same-sex couples won the right to marry nationwide, OUT magazine named President Obama it's "Ally of the Year" Tuesday.

Obama's image on the cover marks the first time a sitting American president has been photographed for an LGBT magazine. Aaron Hicklin, the magazine's editor, boasted in a letter to readers: "I did get that selfie."

Hicklin wrote that he dreamed of "walking in a park, laughing" with Obama as they traversed the streets of Williamsburg in Brooklyn, but even the short time Hicklin spent at the White House made an impression.

"You do not get much time with the president for a photo shoot — about four minutes, five if you’re lucky — and there’s something surreal and tense about kicking your heels in the White House library while waiting for your subject to materialize," Hicklin wrote. "Yet when the president walks into the room — and it’s a small room, lined with books and a few ornamental swords, one gifted to George Washington by the French — the air rushes in with him."

"It’s hard not to be starstruck," he added. "A little turn this way, a little that way, an ice-breaking joke ('this is the only expression I’ve got'), and we are done. The president strides off, the room empties."

While the president opposed same-sex marriage for several years before supporting it in 2012, Hicklin wrote, his "last-minute conversion" gave crucial momentum to the Supreme Court's June 26 ruling to legalize such unions.

"Many things led up to that decision — 'decades of our brothers and sisters fighting for recognition and equality' as the president notes — but once his administration decided to join that fight it created what people like to call a 'transformative' moment," Hicklin wrote. "It helped tip the balance, and it put our elected leader on the right side of justice."

The administration has adopted policies that focus on the rights of lesbian, gay, bisexual and transgender Americans during Obama's second term, including new federal housing protections as well as an executive order barring federal contractors from discrimination based on sexual orientation and gender identity.

[Obama privately backed gay marriage while publicly opposing it, top adviser says]

In an interview with Hicklin, Obama spoke about his early influences regarding gay rights — his mother and a professor at Occidental College — as well as the dramatic shifts in public opinion over the course of his lifetime.

Asked to name the first openly gay person he ever met, the president said he couldn't recall whom that would have been, "But Dr. Lawrence Goldyn, one of my college professors, is a man who stands out to me. I took his class freshman year at Occidental. I was probably 18 years old — Lawrence was one of the younger professors — and we became good friends."

"He went out of his way to advise lesbian, gay and transgender students at Occidental, and keep in mind, this was 1978," added Obama, who recognized Goldyn at the White House's pride celebration in June. "That took a lot of courage, a lot of confidence in who you are and what you stand for."

The president attributed his support for LGBT rights to his understanding what it was like to be marginalized from mainstream society "growing up as a black guy with a funny name" and "because my mom instilled in me the strong belief that every person is of equal worth."

Last week's gubernatorial election in Kentucky may have shown the political popularity of Kim Davis, a clerk in Rowan County, Ky., who went to jail rather than issue marriage licenses for same-sex couples. But Obama told OUT magazine that he would tell her and other local and state officials that the question of whether gay men and lesbians can marry is now settled.

"I am a man of faith and believe deeply in religious freedom, but at the end of the day, nobody is above the rule of law — especially someone who voluntarily takes an oath to uphold that law," Obama said. "That's something we've got to respect."