The veteran principal brought in to overhaul long-struggling Boys and Girls High School is considering abandoning that position after less than two years to take over a school on Long Island, officials confirmed Tuesday.

The move would deal a major blow to the city’s high-stakes bid to revive Boys and Girls, a historic school in Bedford-Stuyvesant, Brooklyn that inspires fierce loyalty among local community leaders but ranks among the worst-performing in the state. It would also be an embarrassing turn of events for top city officials who pinned their transformation plans on the principal, Michael Wiltshire, whom they have continued to back even as he faced a recent string of setbacks.

It also calls into question officials’ decision to let Wiltshire hold onto his old job as head of high-performing Medgar Evers College Preparatory School even as he took over Boys and Girls, as both schools could now start the summer without permanent principals. The city named Wiltshire “master principal” of both schools and gave him a large bonus when he took on the tough assignment.

Wiltshire has interviewed for the principal opening at Uniondale High School on Long Island, but has not yet accepted it, city officials said. In a statement, Wiltshire called the job change “a deeply personal decision” that he would make at the end of the school year.

This week, the city sent another principal, Angello Marra, to assist Wiltshire in running both schools through the end of June.

Wiltshire’s possible departure follows news that the leader of a similarly troubled Brooklyn school, Automotive High School, is leaving her post for a principalship on Long Island. And it comes even as Wiltshire enjoys strong backing from top officials: Chancellor Carmen Fariña told the City Council last week that “having a principal who’s a master principal working in that building has made a difference” at Boys and Girls.

The school’s attendance and graduation rates have improved since Wiltshire took over in Oct. 2014, and its suspension rate has fallen sharply. Still, its enrollment has fallen by nearly 50 percent that period, only half its students currently manage to graduate within four years, and 60 percent are considered chronically absent. State officials have threatened to shut down the school unless it makes major improvements, and its staffers were forced to reapply for their jobs last year.

Boys and Girls’ previous principal left suddenly after clashing with the de Blasio administration over its improvement plans for the school. In order to convince Wiltshire to step in, the city agreed to let him continue to oversee Medgar Evers, a selective school two miles away in Crown Heights, Brooklyn.

Just a few months later, Mayor Bill de Blasio showered Wiltshire with praise, saying that he had kickstarted the revival of Boys and Girls — one of the most closely watched schools in the mayor’s “Renewal” program for struggling schools.

“A great new leader has come here to breathe new life into this school, to create a sense of optimism and spirit again, and to show that the potential can be met,” the mayor said at a press conference at the school in March 2015, where he touted early signs of progress under Wiltshire.

Despite the early gains, Wiltshire has recently faced setbacks at both schools.

A Medgar Evers assistant principal who was helping run the school while Wiltshire was away was removed earlier this year because of a city investigation involving her, forcing Wiltshire to devote more attention to the school. On Tuesday, parents there staged a rally to protest the city’s decision to put Marra partially in charge.

Meanwhile, Medgar Evers’ leadership team rejected Wiltshire’s proposal to move that school into Boys and Girls’ campus — which the city supported — when the other schools in that building pushed back against their demands. And Good Shepherd Services, a social-service agency that has worked with Boys and Girls for several years, decided last week to pull out of the school after repeatedly clashing with Wiltshire.

Top education department officials visited Boys and Girls on Tuesday, then held a meeting with Medgar Evers parents. Rumors circulated among some staffers at Boys and Girls that Wiltshire planned to leave.

“We don’t know what to tell the kids, the parents, nothing,” said a teacher who spoke on the condition of anonymity. She said the uncertainty swirling around Wiltshire was distracting from the school’s work.

“The kids are being overshadowed,” she said, “and that’s who we’re supposed to be here for.”

A spokeswoman for the Uniondale school district said principal candidates for its single high school are still being interviewed and no final decision had been made.

In his statement, Wiltshire said he was working hard to fulfill his duties as principal of both schools, adding that Boys and Girls has dedicated educators and has made “dramatic” improvements.

“At the end of this school year I will determine my next steps, a deeply personal decision that I’ll make in consultation with my family,” he said in the statement, which was sent to Chalkbeat by an education department spokeswoman. “If I decide to accept another position, I will work closely with the DOE, my colleagues, and of course each school community to ensure a seamless transition.”