Carlos Castro owns Todos Market, with two locations in Prince William County. He started catering to non-Latinos after the county’s immigration law passed. (MARGARET THOMAS/MARGARET THOMAS TWP)

Now that the Supreme Court has upheld part of Arizona’s tough law on illegal immigration, Carlos Castro’s Todos Market offers a case study in how Prince William County has fitfully come to terms with a similar law.

Castro had just opened his second Latino grocery store, in Dumfries — his other is in Woodbridge — when Prince William passed a forerunner to the Arizona statute in 2007, allowing county police to check the immigration status of anyone who authorities had “probable cause” to believe was in the country unlawfully.

The county’s red-hot economy had produced a housing and construction boom that triggered a wave of immigration, legal and illegal. But once the law was passed, Latinos left in droves, leaving Castro with a choice: adjust his business model or go bankrupt.

Five years later, Castro’s stores are doing well and serve a clientele that is roughly half Hispanic. His freezers are filled not only with Latino delicacies but also with more mainstream fare — Stouffer’s frozen dinners and T.G.I. Friday’s chicken bites.

“We hit the nail on the head,” Castro said Tuesday, crediting his survival to a spirit of compromise that ultimately prevailed in Prince William.

Latinos have started to return as the county’s economy slowly recovers, but the scars from 2007 remain.

After the immigration law was passed, a wave of protest from Latino groups and advocates — and a concern about racial profiling voiced by the county police chief — triggered a compromise: Police wouldn’t check the immigration status of anyone they thought might be illegal, but everyone arrested would be run through a federal immigration database. Those identified as being in the country illegally would be turned over to federal authorities.

Monday’s Supreme Court ruling struck down aspects of Arizona’s law but left in place something similar to Prince William’s statute: Police will be required to check the immigration status of people they detain and suspect to be in the country illegally.

Corey A. Stewart, chairman of the Prince William Board of County Supervisors, said he’s glad the county reached a compromise, although he doesn’t necessarily disagree with Arizona’s position. He said 4,700 arrestees have been turned over to federal immigration services.

“Ultimately the improvement in public safety and in the business climate is going to yield positive results for Arizona, just as it has for Prince William County,” he said.

Castro said the immediate effect of Prince William’s crackdown could have driven him out of business. But he adapted by asking non-Latino customers what products they wanted most in his store. He wouldn’t have thought to stock things such as Hot Pockets and ready-to-eat meats, but he listened to their feedback.

Now, the 57-year-old former illegal immigrant said that business is back and the environment in Prince William is much less tense.

“A lot of people got involved and made sure our community didn’t unravel,” Castro said. “I think we have learned to live together, and I feel really comfortable in Prince William County.”

But not everyone is as sanguine. Matty Lupo, who works at the largely Latino Holy Family Catholic Church in Dale City, said she would love to leave the county. But she stays, she said, because her children are in a good school.

Lupo said she hears stories almost daily about slights big and small toward Latinos, such as a rude or aggressive police officer who eyes someone for what she and others call “driving while Hispanic.”

She says it’s an attitude inspired by the vitriol of 2007. “Maybe we’re intruders to them,” Lupo said.

County officials say the crackdown has been successful. A 2010 University of Virginia study on the policy in Prince William showed that of the 14,000 arrests made in 2009, 6 percent were of illegal immigrants — though the study didn’t conclusively connect the policy and crime rates.

Though Prince William was one of the areas hit hardest by foreclosure as the economy crashed and the crackdown started, things are now picking up.

Job surveys show that Prince William is among the top localities for job growth in Virginia, and county statistics indicate that violent crime is dropping, although there is debate about how much of that decline is related to the illegal-immigration crackdown.

The county has also filed a lawsuit, still in court, seeking data from the federal government in an effort to determine whether the illegal immigrants the county has turned over have been deported.

Police are still viewed with suspicion in some quarters. Ricardo Juarez, a construction worker who helped organize the group Mexicanos Sin Fronteras (Mexicans Without Borders) and staged mass protests during the immigration debates in Prince William five years ago, said the county is seen as much more anti-Latino than in the past as a result of its policies.

But county officials say that just one complaint of racial profiling has been logged against the county and police department, and that it was dismissed in court.

Police Chief Col. Charlie T. Deane has called Arizona’s measure “a high-risk gamble” and said Prince William’s more “moderate” position has caused fewer problems and has been accepted by more stakeholders, according to a news release from the Police Executive Research Forum.

Castro’s wife, Gladis, busily stocking shelves with cold medicine, said business is getting better because many Latinos who fled to Maryland are coming back. People in the community aren’t talking as much about illegal immigration anymore, she said.

Her husband, who fled El Salvador’s civil war in the 1980s and soon gained legal status, said he is intent on having a store for everyone, but with a Latin flair. He’s even hoping to franchise Todos Market.

When a customer asked for something he had never heard of — beer salt, apparently a staple in parts of Texas — Castro was more than receptive.

“We’re working on that,” he said.

More from The Washington Post:

The GOP’s glimmer of hope with Latinos

Supreme Court ruling may help Obama woo Latino votes

Latino worker’s union reacts to immigration ruling