COLUMBIA, S.C. — South Carolina, the first state to secede from the Union and one that has quarreled often, in the ensuing years, over matters the Civil War never quite settled, dispatched with at least one of those issues on Thursday as Gov. Nikki R. Haley signed into law a bill to remove the Confederate battle flag from the grounds of the State House.

Ms. Haley, a Republican, first passionately called for the flag’s removal on June 22. She signed the legislation in a state capitol where, the night before, members of the House of Representatives had squared off in an impassioned 15-hour legislative feud over the legal issues that would allow for the permanent furling of the flag, which was introduced on the capitol grounds in the early 1960s at the height of segregationist sentiment.

“The Confederate flag is coming off the grounds of the South Carolina State House,” Ms. Haley said during the signing ceremony in a lobby packed with lawmakers, tourists and dozens of police officers. She added: “Twenty-two days ago, I didn’t know that I would ever be able to say this again, but today, I am very proud to say that it is a great day in South Carolina,” referring to a phrase that the promotion-minded governor, in 2011, told state employees to use when answering their work phones.

Also in attendance were family members of the nine victims of the June 17 massacre in a predominantly black church in Charleston, S.C., an event that ignited calls for the flag to come down. All nine families were to receive one of the pens Ms. Haley used to sign the bill into law.

The battle flag, which flies in front of the graceful 19th-century state building here, is now set to come down at 10 a.m. Friday. It will be a moment many South Carolinians, supporters and opponents of the flag alike, never thought they would witness.

Image

Gov. Haley of South Carolina on Thursday signed the bill to remove the Confederate battle flag from the grounds of the South Carolina State House.CreditStephen B. Morton for The New York Times

“I thought that the powers that be would never acquiesce or see it the way that so many people see it, and that is that that flag doesn’t unite people; it divides people,” said Representative Cezar E. McKnight, a Democrat, who is black.

For Ms. Haley, a second-term governor who many here believe covets national office, the lowering of the flag will count as a major political achievement. Even her longtime critics praised her for skillfully dismantling a passion-packed bomb of an issue.

Because Ms. Haley is subject to term limits and cannot seek re-election, she is somewhat immune from the fierce opposition of flag supporters. At the same time, her handling of the crisis has significantly raised her national profile, arguably for the first time since 2010, when the former vice-presidential candidate Sarah Palin endorsed Ms. Haley’s fledgling campaign for governor.

“I’ve got to hand it to her — in this tragedy she was just outstanding,” said David Woodard, a political science professor at Clemson University and a Republican consultant who worked for one of Ms. Haley’s opponents in the 2010 primary.

And for the nation, it will serve as dramatic notice that many of the Confederate signs and symbols that have long dotted the Southern landscape may now be vulnerable to revision and removal. This wave of scrutiny of Old South symbols has been embraced by some and rejected by others.

Video

On Wednesday night, South Carolina’s state legislature voted to remove the Confederate battle flag from its State House grounds. The debate intensified in the days leading up to the decision.CreditCreditJohn Bazemore/Associated Press

In Washington, Democrats and Republicans have clashed about Confederate flags on National Park Service property. In New Orleans, Mayor Mitch Landrieu, a white Democrat, asked the City Council on Thursday to consider rechristening a major thoroughfare named for Jefferson Davis, the Confederate president, and moving the statue of Robert E. Lee from his namesake traffic circle downtown.

Throughout the day on Thursday, dozens of South Carolinians gathered near the flag at the State House in Columbia, and the towering Confederate veterans monument in front of it, to photograph it or to reflect. Black and white families snapped selfies. One protester hoisted his own Confederate flag. Others waved the Stars and Stripes.

Some were jubilant: ‘Yeah y’all!!” read a sign held by a middle-aged white man. “It’s coming down.”

And some were chagrined. Michael French, 43, a contractor who lives outside Columbia, came with his son Chandler, 17, to photograph the flag before it came down.

“Biblically speaking, anytime there’s something that causes division among men, it should be done away with,” said Mr. French, who is white. “But I don’t think that applies here, because there will always be something else” for people to protest, he said.

Next, his son predicted, “they’re going to want to take down the Confederate monument. Everybody wants to be a victim.”

Image

The signs held by demonstrators like Maria Calef of Columbia, S.C., on Thursday expressed relief after days of demands that the Confederate battle flag be removed.CreditStephen B. Morton for The New York Times

A few locals, like Catherine Hart, 66, remembered the days in the early 1960s when she and other African-Americans marched down Main Street, the downtown thoroughfare that ends at the Confederate memorial, to demand that they no longer be relegated to the backs of buses and excluded from lunch counters.

“As a whole, we’re moving forward,” she said. “And thank you, Lord.”

In Charleston on Thursday, people continued to flock to Emanuel African Methodist Episcopal Church, the site of the shootings, to pay their respects.

Camryn Singleton, the 15-year-old daughter of Sharonda Coleman-Singleton, one of those killed, stood off to the side beneath a tree, marveling at all the visitors. “South Carolinians are a stubborn bunch of people if it took something crazy like this to happen to make that happen,” she said. “But it’s really good they’re taking it down. That’s the one good thing that’s come out of all this — is all the people who have come together, and all the people who have been helping each other.”

The fate of the flag had been uncertain just hours before. The bill calling for its removal had sailed through the State Senate, but approval by the State House was more of a challenge. A number of lawmakers retain strong feelings for the flag, seeing it as a means of honoring the Confederate dead.

After hours of procedural maneuvers and speeches that touched on the state’s past glories and sins, the House eventually passed the bill, 94 to 20, in a roll-call vote that came after 1 a.m.

Some opponents have been gracious in defeat. “The battle is over,” Representative Michael A. Pitts, a Republican from Laurens County who had repeatedly tried to amend the proposal, said Thursday. “My side lost. We’ll come back together. The state will move on.”

Others were defiant. The Ku Klux Klan has announced that it will hold a rally in Columbia on July 18. And the Sons of Confederate Veterans, who unlike the Klan say their allegiance to the flag is about heritage not race, has sharply criticized the flag’s removal. In a statement on Thursday, Charles Kelly Barrow of the group said it was part of a “wave of cultural cleansing” that “sullies” the names of their Confederate ancestors.

Still, Mr. Woodard, evoking the old saying here that South Carolina is “too small to be a Republic and too large to be an insane asylum,” said that the flag’s removal felt like a rare moment of his state doing the right thing after a string of embarrassments and missteps dating to 1861.

Whether the effects of the vote will be more than symbolic remains unclear. The N.A.A.C.P., which has for the last 15 years imposed an economic boycott on the state over the flag, will consider lifting the boycott at its yearly convention, which will begin Saturday in Philadelphia, Cornell William Brooks, the president of the group, said Thursday.

But few here believed it would do much to alleviate the state’s 27 percent child poverty rate, or the polarization of politics along racial lines, or the bitter fights over the role of government in addressing such issues.

At the signing ceremony on Thursday, Ms. Haley noted, as she had previously, that South Carolinians could be proud of the families of the slain churchgoers, who showed the world how to forgive, she said, when they absolved the suspect, Dylann Roof.

Ms. Hart, the African-American woman sitting on the State House steps on Thursday, expressed a magnanimity that was almost as shocking. “My heart goes out to the Klan, because they’re people, also,” she said. “I wouldn’t want to see people suffer.”

“But a change had to come,” she added. “We’re no longer that Deep South state anymore.”

A version of this article appears in print on , on Page A16 of the New York edition with the headline: South Carolina Settles Its Decades-Old Dispute Over a Confederate Flag . Order Reprints | Today’s Paper | Subscribe