WASHINGTON — President Barack Obama, who himself has acknowledged an evolution over gay rights, said Friday that the Supreme Court's ruling giving same-sex couples the right to marry nationwide represents a day when justice "arrives like a thunderbolt."

The president, in a Rose Garden statement before dozens of White House aides, said that the court ruling has "made our union a little more perfect."

Obama didn't announce his own support for gay marriage until 2012 but had championed other aspects of gay rights, including a push to have Congress end the military's don't-ask-don't-tell policy in 2010. The policy officially ended in 2011.

For Obama, the ruling capped three days of upbeat, legacy building events, starting with congressional support for his trade agenda and Thursday's Supreme Court's decision to uphold a key piece of his landmark health care law.

But the day also offered Obama a jarring juxtaposition of emotions as he promptly left the White House to deliver a eulogy at the funeral for Rev. Clementa Pinckney, a state lawmaker and pastor of the historic Emanuel African Methodist Church in Charleston, South Carolina, where Pinckney and eight others were killed by a white gunman last week.

In his remarks, Obama said the court's gay marriage ruling will end the patchwork of laws on marriage across the country and the uncertainty that they create for same-sex couples.

"This decision affirms what millions of Americans already believe in their hearts," he said. "When all Americans are treated as equal, we are all more free."

Immediately after the court ruling, Obama tweeted: "Today is a big step in our march toward equality. Gay and lesbian couples now have the right to marry, just like anyone else. #LoveWins." Likewise, first lady Michelle Obama tweeted: "This decision recognizes the fundamental truth that our love is all equal. Today is a great day for America. #LoveWins"

As staffers began to fill the Rose Garden ahead of his remarks, Obama sat in his Oval Office in shirt sleeves and telephoned the lead plaintiff in the case, James Obergefell, who took the call on the plaza in front of the Supreme Court.

The president told Obergefell that his case was "going to bring about a lasting change in this country. It's pretty rare when that happens."

Obergefell said it was "stunning" to get the call, adding that it was "not something I ever dreamed of."

Meanwhile, the White House changed the profile avatar on its Twitter account to a rainbow-colored image of the White House.