Gov. Charlie Baker on Tuesday signed a bill that will allow for the temporary removal of firearms from people considered a danger to themselves or others.

The new Massachusetts law lets a relative or someone else with close ties to a legal gun owner petition a court for an up-to-12-month extreme risk protection order if the individual is exhibiting dangerous or unstable behavior.

The individual can appeal the decision.

The so-called "red flag" bill was given final approval by the Massachusetts House and Senate last week. It goes into effect immediately.

“Massachusetts’ gun laws are a model for the nation, and creating an additional pathway to keep guns away from people unfit to possess them will make our laws even stronger," Baker, a Republican, said in a statement.

He said the law "creates a responsible way to help prevent gun deaths and suicides while protecting individuals’ second amendment rights."

A WBUR poll in March — conducted after the February mass shooting at a school in Parkland, Florida — found that 89 percent of Massachusetts voters said they would support an extreme risk protection order.

"There's a reason why Massachusetts has the lowest gun fatalities and the most commonsense gun laws," said Cambridge Democratic Rep. Marjorie Decker, who sponsored the bill. "This law will now just continue to add to that. It's going to save lives."

The Gun Owners' Action League of Massachusetts, on Twitter Tuesday, said the bill "revokes due process only for licensed gun owners."

Massachusetts joins several other states with "red flag" laws on the books.

The new law also creates a licensing procedure for stun guns in Massachusetts after the state's highest court ruled a blanket ban on the devices was unconstitutional.

With reporting by The Associated Press and the WBUR Newsroom