Thousands of interns poised to flood New York City’s offices and institutions this summer may be unpaid. But come June, their legal standing will be improved.

Mayor Bill de Blasio on Tuesday signed into law a measure intended to ensure that unpaid interns in the city will have the right to sue if they are harassed or discriminated against by an employer — a right, it turns out, that was not reflected in the city’s civil rights code.

The legislation, which passed unanimously in the City Council and takes effect in June, was prompted by a sexual harassment suit brought last year by an unpaid intern in the New York office of a Chinese news agency, Phoenix Satellite Television, who said she was harassed and groped by her supervisor.

The harassment claim was thrown out by a federal judge, who found that the intern did not qualify as an employee because she was not being paid, and thus did not have the standing to sue under New York State and City human rights laws, which prohibit discrimination against workers.