Gov. Deval Patrick on Wednesday signed a sweeping overhaul of Massachusetts' gun laws, a measure he said will help curb gun violence, protect families and build safer communities.

The new law stiffens penalties for some gun-based crimes, creates a Web-based portal within the state Executive Office of Public Safety to allow for real-time background checks in private gun sales and calls for the creation of a firearms trafficking unit within the state police.

It also gives local police chiefs the right to go to court to try to deny firearms identification cards needed to buy rifles or shotguns to people they feel are unsuitable to have access to the weapons.

Police chiefs currently have the right to deny "licenses to carry" to individuals they feel are unsuitable to carry handguns. The new law retains that authority, but would require police chiefs to give written reasons for any applications they choose to deny. Their decisions would have to be based on public safety and could be appealed in court.

Patrick signed the bill at a ceremony at the Statehouse.

"Our communities and our families are safer when irresponsible gun sales and use are reduced," he said.

Another part of the law mandates Massachusetts join the National Instant Background Check System, which requires the state to transmit information about substance abuse or mental health commitments to a federal database that police can use to review firearms applications.

Patrick has praised the measure, despite the fact that lawmakers failed to include his proposal that would have limited individuals to the purchase of no more than one gun per month.

The new law also increases the penalty for carrying a firearm on school grounds; increases the punishment for being armed with a firearm while carjacking; creates penalties for transporting firearms into the state for criminal activity or unlawful distribution; establishes penalties for gun dealers who fail to report a lost or stolen weapon and mandates that an individual whose license to carry firearms has been revoked, suspended or denied must surrender all guns in their possession.

Work on the bill began last year after the 2012 mass school shooting that left 20 children and six adults dead at Sandy Hook Elementary School in Newtown, Connecticut.

Massachusetts already has some of the strictest gun laws in the country.

Other portions of the legislation are designed to improve security for students and teachers.

The new law requires schools have access to two-way communication devices with police and fire departments and mandates school districts provide two hours of suicide awareness and prevention training to school personnel every three years.

The law takes effect immediately.

Patrick also signed into law Wednesday an economic development bill and a $2.2 billion, four-year environmental bond bill.

Among the dozens of spending projects in the environmental bond law is $100 million for the dredging of Boston and New Bedford harbors and another $100 million for the Department of Conservation and Recreation for the design, construction and preservation of forests, parks, harbor islands and other recreational facilities.

The law also is intended to help pave the way for construction of the New Bedford Marine Commerce Terminal, the first facility in the nation designed to help build, assemble, and deploy of offshore wind energy projects.

Earlier: