RICHMOND — The national firestorm over an Indiana law that some say legalizes discrimination against gay and lesbian people has spilled over into a Virginia House of Delegates race.

Del. Robert G. Marshall (R-Prince William) is defending the Indiana law, to the chagrin of his Democratic challenger, Don Shaw, who called the effort “offensive.”

Marshall said the law signed by Indiana Gov. Mike Pence is similar to a law that Virginia has had on the books for years.

“Virginia has the same law. We passed it in 2007. The sky did not fall!” Marshall wrote in a letter to the Indianapolis Star.

Marshall wrote the letter in response to one that Gov. Terry McAuliffe (D) wrote to the newspaper imploring Indiana businesses to consider relocating to Virginia for its “open, inclusive and thriving business environment.”

Shaw and the governor’s office said there are significant differences between Virginia’s law — and similar ones in other states — and the law under scrutiny in Indiana.

They say Indiana’s law was designed to give private companies legal cover for discrimination against gay and lesbian people, while Virginia’s law seeks to protect an individual’s freedom of religion from government intrusion.

McAuliffe spokesman Brian Coy said Marshall “misunderstands the spirit’’ of the governor’s letter to the Indianapolis newspaper.

“Our law does not confer religious rights explicitly on for-profit entities. It is not designed to give them a legal defense in a case where the government is not involved,” Coy said.

Shaw said he is running in part to support laws protecting his 23-year-old son, who is openly gay.

“Bob Marshall wants to basically allow people to discriminate against my son and I don’t think that’s right,” he said. “I want to live in a robust and thriving Virginia economy and I believe Bob Marshall is doing everything he can do to prevent that.”

In an interview, Marshall, acknowledged that Virginia and Indiana’s laws are not identical, but said, “you can’t fault” Indiana for updating its law to reflect the Supreme Court’s ruling in the Hobby Lobby case. The 2014 ruling said some businesses do not have to offer contraceptive coverage that conflicts with the owners’ religious beliefs.

During the recent legislative session, Marshall introduced two bills that Shaw said mirror the Indiana law.

One would have blocked McAuliffe from making nondiscrimination against people because of their sexual orientation a condition of entering into a government contract. The other said anyone who gets a license or authority from the state would not have to serve or counsel same-sex couples if he or she has moral or religious objections.

“Advocates on one side of this compulsion do not want a public authority to recognize — even in a minute way — that there’s a moral objection to immoral behavior,” Marshall said.

Marshall said the bills, which went nowhere, were prompted by the rapid legalization of same-sex marriage around the country — and an opinion that Attorney General Mark Herring (D) issued giving local school boards the authority to include sexual orientation and gender identity in their anti-discrimination policies.

Marshall, one of the most conservative members of the Virginia House, was the author of Virginia’s now defunct 2006 ban on same-sex marriage.