Mr. Taylor, who had been trailing, sent a letter on Sept. 3 to Mr. Kobach, saying that he was withdrawing. Several prominent Democrats are said to have been instrumental in nudging him to do so to clear the way for the independent, Greg Orman, who has been leading Mr. Roberts in some recent polls. Mr. Kobach, who is a member of Mr. Roberts’s honorary campaign committee, said that Mr. Taylor had failed to meet the requirements for removing his name from the ballot. Kansas law says candidates can be removed from the ballot if they die or declare that they are unable to complete the duties of office.

Mr. Taylor petitioned the state Supreme Court, and in an opinion Thursday afternoon, the court, which is dominated by Democratic appointees, ruled unanimously that Mr. Kobach had erred in refusing to accept Mr. Taylor’s letter and ordered that his name be removed before ballots are mailed to overseas military personnel, a process that was scheduled to begin Saturday.

Mr. Kobach said Thursday that he would require the Democrats to select a replacement, a step he insisted was required by law. Mr. Kobach said he would extend the deadline to mail those ballots so the Democrats could pick someone else. If the party refuses to do so by noon next Friday, Mr. Kobach said he would “review our legal options.”

A spokesman for the Kansas Democratic Party, did not respond Thursday to questions about whether his party would name a new candidate. But in a statement, the state Democratic Party chairwoman, Joan Wagnon, praised the ruling and said “democracy is threatened” with Mr. Kobach as secretary of state.

Mr. Orman, a 45-year-old former energy entrepreneur, has notably refused to commit to caucusing with the Democrats if he wins.