The 12-day lock-out of unionized faculty members at LIU Brooklyn ended Wednesday night — hours after a student demonstration — with the university administration saying professors will teach their scheduled classes on Thursday.

The American Federation of Teachers, which has backed the local union, said in a news release that the faculty’s contract has been extended to May 31 and that a mediator will be involved in future negotiations between LIU and the Long Island University Faculty Federation. The contract had expired Aug. 31.

Jessica Rosenberg, president of the local union, said the faculty “is relieved this is over and is looking forward to immediately returning to the classroom to get started with the semester.”

Randi Weingarten — president of the nation’s second-largest teachers union, who joined demonstrators on the streets outside campus last week — declared the agreement “a huge win” for students’ “right to a real education” and said the AFT will continue to support the faculty.

The union represents about 400 full-time and adjunct professors at the campus in downtown Brooklyn.

Gale Haynes, LIU chief operating officer and university counsel, said in a statement that “the union’s commitment not to strike during this academic year provides us enough runway to reach a reasonable and fair agreement, while providing our students the ability to continue their studies uninterrupted.”

Haynes called mediation “a positive step to that end.”

The instructors had been locked out of their offices since Sept. 3 — the Saturday before the start of fall semester classes last week. The administration said the measure was to prevent a strike after the two sides could not agree on a new contract.

On Sept. 6, faculty on the Brooklyn campus voted no confidence in Kimberly R. Cline, LIU’s president. Two days later, the LIU Post faculty at the Brookville campus followed suit.

Word of Wednesday night’s breakthrough came roughly six hours after the latest demonstration in downtown Brookyn. About 30 to 40 faculty members stood outside the campus gates on Flatbush Avenue and shouted, “Let us teach!” A group of students on the other side of the gates replied, “Let us learn!”

The students, holding signs — including one that said “Students deserve the best educators” — later walked off campus and joined their professors for a rally, calling on Cline to let the unionized faculty return to work.

Some of a half-dozen students interviewed Wednesday said they had come to classes since the semester began, but no faculty member was there to teach.

“I’ve been to classes and there is nobody there at all — no substitute, no staff,” said Jessica Estevez, 24, of Far Rockaway, a graduate student studying to become a speech pathologist.

As the labor dispute continued, the AFT brought more pressure to bear, with Weingarten asking credit analysts to consider the financial impact it was having on LIU — both its Brookville and Brooklyn main campuses.

Weingarten sent a letter to the higher education division at Moody’s Investors Service calling attention to the “serious situation” occurring on the Brooklyn campus, union officials said earlier Wednesday.

“As the administration drags students through a protracted faculty lockout, we worry that LIU’s reputation could be damaged for years to come,” Weingarten wrote.

A spokesman with Moody’s did not respond to a request for comment Wednesday.

After the announcement late Wednesday of the agreement, it was unclear if the AFT would retract the letter to the rating agency.

The appeal to Moody’s could affect the university as a whole because all campuses and branches are covered under one budget. The university is a private, nonprofit entity that is heavily dependent on student tuition, which for full-time undergraduates is about $34,000 for the 2016-17 academic year.

In January, Moody’s affirmed LIU’s Baa3, medium-grade credit rating. Debt at that rating holds moderate financial risk for investors, according to the credit-ratings agency’s chart of definitions, which range from Aaa to C.

The rating reflects management’s commitment to generating operating surpluses, good growth of cash and investments, and large size and scale with multiple campus locations, according to that January report.

LIU’s administration and the faculty members have been at odds over pay and cuts to health benefits.

Union officials contended that professors and instructors at LIU Brooklyn are paid significantly less than their counterparts at LIU Post in Brookville. University officials have said the Brooklyn faculty is asking for a contract that LIU can’t afford.

Faculty at the Brooklyn and Brookville campuses are represented by different collective bargaining units and are not on the same negotiating schedule, officials said.

The AFT and the Brooklyn faculty union also had asked the university’s accrediting agency — the Middle States Commission on Higher Education — and 13 other nongovernmental agencies that accredit LIU’s academic programs to investigate whether LIU is meeting accreditors’ standards for providing quality instruction to students, a union official said.

Those letters were sent earlier this week.

LIU Brooklyn, LIU Post and the school’s smaller branch campuses in Brentwood, Riverhead and the Hudson Valley are considered to be one university by Middle States, a spokesman for the commission said.

LIU Brooklyn had an enrollment of 8,170 students in fall 2015, according to federal education data, the most recent figures available. The LIU Post campus in Brookville had 8,623 students at that time.

Enrollment numbers for the current fall semester were not available.