SEATTLE — The Washington Supreme Court upheld most of the state’s charter school law Thursday, eliminating the specter that a dozen schools serving about 3,400 students might have to close. Teachers unions, civil rights groups and others had challenged the charter school law, arguing that using public money to operate alternative, nonprofit charter schools over which voters have no direct control violated the state Constitution. A majority of the court rejected most of their arguments but struck down part of the law that restricted the ability of charter school employees to unionize. The Washington State Charter Schools Association cheered the ruling, which appeared to end decades of fighting over the schools in Washington, as a “win for public education” and a “big step forward in the fight to close the opportunity gap that persists in our state.” Patrick D’Amelio, its chief executive, declined to immediately comment on the part of the law that was struck down, saying the association needed time to review the decision to understand its significance. “The Washington Supreme Court has given 3,400 students and their families from across our state new hope by affirming that charter public schools will continue to be a valuable part of our public education system,” the organization said in a statement. Most states allow charter schools.