SELMA, Ala. — As a new generation struggles over race and power in America, President Obama and a host of political figures from both parties came here on Saturday, to the site of one of the most searing days of the civil rights era, to reflect on how far the country has come and how far it still has to go.

Fifty years after peaceful protesters trying to cross a bridge were beaten by police officers with billy clubs, shocking the nation and leading to passage of the landmark Voting Rights Act of 1965, the nation’s first African-American president led a bipartisan, biracial testimonial to the pioneers whose courage helped pave the way for his own election to the highest office of the land.

But coming just days after Mr. Obama’s Justice Department excoriated the police department of Ferguson, Mo., as a hotbed of racist oppression, even as it cleared a white officer in the killing of an unarmed black teenager, the anniversary seemed more than a commemoration of long-ago events on a black-and-white newsreel. Instead, it provided a moment to measure the country’s far narrower, and yet stubbornly persistent, divide in black-and-white reality.

In an address at the scene of what became known as “Bloody Sunday,” Mr. Obama rejected the notion that race relations have not improved since then, despite the string of police shootings that have provoked demonstrations. “What happened in Ferguson may not be unique,” he said, “but it’s no longer endemic. It’s no longer sanctioned by law or custom, and before the civil rights movement, it most surely was.”

Video

President Obama addressed a crowd of thousands on the 50th anniversary of civil rights demonstrations in Selma, Ala.

But the president also rejected the notion that racism has been defeated. “We don’t need the Ferguson report to know that’s not true,” he said. “We just need to open our eyes and our ears and our hearts to know that this nation’s racial history still casts its long shadow upon us. We know the march is not yet over; we know the race is not yet won. We know reaching that blessed destination where we are judged by the content of our character requires admitting as much.”

An estimated 40,000 people, most but not all African-American, gathered on a sunny, warm day in this small town of elegant if weathered homes and buildings to mark the occasion. The celebration had a festival feeling, with vendors hawking barbecue, funnel cakes, hamburgers and posters of Mr. Obama, the Rev. Dr. Martin Luther King Jr., Muhammad Ali and others. They came from near and far, some lining up before 6:30 a.m. to make sure they got in.

Ferguson was on the minds of many. Dontey Carter, 24, even came from Ferguson, saying he wanted to make a connection with protests he took part in back in Missouri. “I feel like it’s critical for me to be here,” said Mr. Carter, wearing a T-shirt with the words “We Are Justice” on the front. “The same tactics they used in Ferguson is kind of close to what they did here.”

Bridgette Traveler, 48, a disabled Army veteran who came from Shreveport, La., was in Ferguson last year protesting the fatal police shooting of Michael Brown.

Image

President Obama with Representative John Lewis in Selma, Ala. Mr. Lewis was injured in the march there 50 years ago.CreditDoug Mills/The New York Times

“We have a long way to go when Michael Brown was killed for just walking down the street,” Ms. Traveler said.

Some attendees still angry about the Ferguson case interrupted Mr. Obama’s speech, banging a drum, holding up signs that read “Stop the Violence” and chanting “We Want Change.” Others in the audience tried to quiet those responsible for the outbursts, but eventually police officers — three white and two black — carried off one protester.

Joining Mr. Obama on Saturday was former President George W. Bush, who signed the reauthorization of the Voting Rights Act in 2006, as well as more than 100 members of Congress. About two dozen of them were Republicans, including the House majority leader, Kevin McCarthy of California. While sitting onstage, Mr. Bush made no remarks, but rose to his feet to applaud Mr. Obama, and the two men hugged afterward.

Speaker John A. Boehner of Ohio and Senator Mitch McConnell of Kentucky, the Republican majority leader, did not attend, nor did most Republican presidential candidates, who were in Iowa campaigning. But the Republican-led Congress voted to award the Congressional Gold Medal to the “foot soldiers” of Bloody Sunday as “an expression of our affection and admiration for those who risked everything for their rights,” as Mr. Boehner put it.

Video

Gay Talese reflects on how events in Selma, Ala., affected race relations in the United States.

Several prominent Democrats were missing, too. Former President Bill Clinton and Hillary Rodham Clinton, who is preparing to run for the White House next year, were in Miami for an event sponsored by the Clinton Global Initiative. In the Clintons’ adopted state of New York, about 250 people marched across the Brooklyn Bridge in commemoration of Selma.

Gov. Robert Bentley, a Republican who spoke in Selma on Saturday, said he hoped the occasion would show how much Alabama has changed. “We want people in America and the world to realize that Alabama is a different place and a different state than it was 50 years ago,” Mr. Bentley said in an interview. “It has become probably as much of a colorblind state as any state in the country, and we’re very proud of the advancement we’ve made.”

But that was not a universal view in a state where Mr. Obama received just 15 percent of the white vote in 2012.

“I think in many ways we’ve gone backwards on race in this country,” former Representative Artur Davis of Alabama, who is African-American and switched parties to become a Republican, said in an interview. “There’s obviously a very deep racial divide in Alabama when it comes to President Obama.”

Image

An estimated 40,000 people attended the event.CreditDoug Mills/The New York Times

Alabama is also on the front lines of what some see as the modern-day successor to the civil rights movement. Although a federal court threw out the state’s ban on same-sex marriage, Alabama’s Supreme Court has tried to block the issuance of marriage certificates. Mr. Obama made several references to gay rights but did not directly address the fight over marriage in Alabama.

He did take the opportunity to implicitly fire back at Rudolph W. Giuliani, the former New York mayor, who recently questioned his patriotism. The president cited the bravery of the marchers who risked everything 50 years ago to stand up for their rights.

“That’s what it means to love America,” Mr. Obama said. “That’s what it means to believe in America. That’s what it means when we say America is exceptional.” The president added later in his address, “That’s what America is, not stock photos or airbrushed history or feeble attempts to define some of us as more American as others.“

The events of March 7, 1965, proved a turning point in the civil rights movement, recently depicted in the movie “Selma.” When 600 demonstrators embarking on a 50-mile march to Montgomery for voting rights crossed the Edmund Pettus Bridge, named for a grand dragon of the Ku Klux Klan, state troopers and Sheriff Jim Clark’s posse attacked with billy clubs and tear gas. Among the 17 hospitalized was John Lewis, who suffered a skull fracture. National revulsion helped President Lyndon B. Johnson push the Voting Rights Act through Congress.

Mr. Lewis, 74, who has gone on to a long career in Congress, was on hand Saturday, as were Mr. Johnson’s daughters and a daughter of George Wallace, Alabama’s segregationist governor. The crowd turned exceptionally quiet as Mr. Lewis, speaking in the deep preacher’s cadence for which he is famous, turned around, looked at the bridge where he was nearly killed and described what it was like on that day. “Our country will never be the same because of what happened on this bridge,” he said.

A voting rights workshop later in the day underscored the continuing battles over the law. The Supreme Court struck down the heart of the Voting Rights Act in 2013, in effect deeming it outdated and freeing nine states, including Alabama, to change election laws without advance approval. Mr. Obama called on lawmakers here to return to Washington and pass legislation reviving the act.

But in an era of low turnout, the president said Americans as a whole needed to use their franchise. “What’s our excuse today for not voting?” he asked. “How do we so casually discard the right for which so many fought? How do we so fully give away our power, our voice, in shaping America’s future?”

Correction:March 7, 2015

A picture caption with an earlier version of this article misidentified the city in Alabama where President Obama was photographed. It was in Montgomery, Ala., not Selma, Ala.

Julie Hirschfeld Davis contributed reporting from Washington.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Work of Selma ‘Not Yet Over,’ President Says. Order Reprints | Today’s Paper | Subscribe