Tens of thousands of foreign-born, American-educated students and recent graduates can breathe a sigh of relief.

Earlier this month, the Department of Homeland Security unveiled an anxiously awaited replacement to its popular student visa program for on-the-job training at science, technology, engineering and math firms: the STEM extension to the "optional practical training" program, or OPT, which a federal judge vacated Aug. 12, leaving as many as 50,000 highly educated STEM workers and their employers in limbo.

The new rules, proposed Oct. 19, address concerns from supporters and critics, lengthening the program to allow participants both more training and an additional shot to apply for a coveted H-1B foreign-worker visa, while at the same time expanding federal oversight to prevent employers from allegedly replacing U.S. workers with cheaper foreign talent.

The proposal all but ensures Homeland Security will meet a six-month deadline to replace the old program, which Judge Ellen Segal Huvelle of the District Court of the District of Columbia, ruling in a lawsuit brought by a labor union of high-tech workers, had set to expire in February because of procedural issues with the rule's implementation in 2008.

If Homeland Security missed the deadline, most participants would have been forced to either re-enroll in expensive graduate schools to retain their student visas or leave the country altogether, taking their expertise with them.

"The DHS announcement should mean that STEM OPT is saved," Bob Whitehill, immigration lawyer at Fox Rothschild in Pittsburgh, writes in an email to U.S. News.

The new rules will significantly change the length of the STEM extension. Participants will be allowed to remain in the OPT program for as long as three years – up from two-and-a-half years under the previous regulations.

The expansion allows workers more time to train in the kinds of high-tech, highly specialized fields that often have steep learning curves. For those undertaking research projects, it also grants them crucial extra months in the long process of applying for grants, performing their studies, analyzing the results, then publishing the findings.

But perhaps most critically, the extension gives OPT STEM participants a pivotal third opportunity to apply for a longer-lasting H-1B work visa, which was awarded to only a third of its nearly quarter-million applicants in the last fiscal year.

"The more chances you get, the more years you can try," says Emily Lopez Neumann, an attorney at the Texas-based immigration firm Reddy & Neumann.

The new rules will also introduce a set of protections for both U.S. and foreign workers. The group that brought the federal lawsuit, the Washington Alliance of Technology Workers, or WashTech – a chapter of the Communications Workers of America – had alleged that companies were exploiting the OPT STEM extension to replace American workers with younger, cheaper foreign labor.

Under the new regulations, employers will be required to submit formal mentoring and training plans for their OPT STEM workers – similar to requirements for foreigners obtaining J-1 educational and cultural visas. Companies will also be required to pay those workers the same wages as their American counterparts.

Employees on the OPT STEM extension will also have had to obtain their degrees from accredited institutions, both to protect foreign students from exploitation from unscrupulous for-profit colleges, and also to prevent them from knowingly enrolling in degree mills merely to take advantage of the OPT STEM extension.

"They took into account the issues raised by WashTech and raised by the court in the litigation and worked this into their reasoning behind the changes they were trying to make," Neumann says.