The league said it would make an announcement about where the February game would be played in the coming weeks.
The NBA also said it hopes to hold the 2019 game in Charlotte "provided there is an appropriate resolution to this matter."
Gov. Pat McCrory slammed the decision.
"The sports and entertainment elite, (N.C.) Attorney General Roy Cooper and the liberal media have for months misrepresented our laws and maligned the people of North Carolina simply because most people believe boys and girls should be able to use school bathrooms, locker rooms and showers without the opposite sex present," the governor said. "Left-wing special interest groups have no moral authority to try and intimidate the large majority of American parents who agree in common-sense bathroom and shower privacy for our children."
NBA Commissioner Adam Silver had worked with other NBA officials to try to get North Carolina to change the law, which requires people to use bathrooms in government buildings, schools and universities that correspond to their gender at birth and prevents local governments from passing anti-discrimination ordinances. The law does not apply to facilities in privately owned buildings.
Turner Broadcasting, which broadcasts the game on TNT, released a statement
supporting the decision.
"At Turner, and our parent company Time Warner, diversity in all its forms is core to our value system and to the success of our company," said Turner, which comprises CNN.
"Laws to the contrary go against our fundamental belief of equality and inclusion for all individuals. We fully support the NBA's decision to relocate the 2017 All-Star Game and all of the weekend's events originally scheduled to be held in Charlotte, North Carolina."
Earlier this month, the law, which initially passed in March, survived largely unscathed after last-minute wrangling at the close of the state legislative session.
The measure was modified to restore workers' rights to use state law to sue over employment discrimination. McCrory, who requested the change, signed the legislation on Monday.
Still, most of the provisions that outraged gay rights advocates, entertainers and business leaders remained.
"Since March, when North Carolina enacted HB2 and the issue of legal protections for the LGBT community in Charlotte became prominent, the NBA and the Charlotte Hornets have been working diligently to foster constructive dialogue and try to effect positive change," the NBA's statement read.
The All-Star Game is scheduled to be held in February. Yahoo reported officials are looking to hold the game in New Orleans instead. New York also is a possibility, ESPN reported.
New York Mayor Bill de Blasio said the city would welcome the festivities, which also include a celebrity game, a rising stars game, dunk contest, a development league all-star game, a skills challenge and 3-point shooting contest.
The team that would have hosted the weekend's events said it understood the NBA's decision.
"There was an exhaustive effort from all parties to keep the event in Charlotte, and we are disappointed we were unable to do so," the Charlotte Hornets said.