TWO MONTHS after they tried to shut down ride-sharing services that allow users to hail a car using a smart phone app, Virginia officials have shifted gears. They struck an agreement with Uber and Lyft, two of the biggest ride-sharing companies, that will allow the companies to continue operating under rules that provide sensible protections for passengers and an alternative means of transport that has proved increasingly popular with the public. This move could offer a template for other states, including Maryland, where last week the body that oversees utilities and transportation ruled that ride-sharing companies should be subject to state regulation.

The impulse to stifle companies like Uber has been on display in a number of U.S. and European cities where long-established taxi companies see ride-sharing as a threat to their business model. Cab drivers saw the new ride-sharing firms, free of licensing and regulatory requirements, as enjoying a competitive leg up. They cried foul; in some cases, policymakers overreacted.

In fact, the cabbies were right, up to a point. It’s reasonable to adopt regulations for the new hail-by-app car industry. The trick is to tailor those regulations so that they protect passengers without stifling competition. Virginia appears to have managed that.

The new rules mandate background checks for drivers that will disqualify those with serious criminal records, including sex offenders, as well as any with poor driving records — especially if they include drug or alcohol violations. The burden for collecting and maintaining drivers’ records will rightly be on the ride-sharing companies.

In addition, Uber and Lyft cars must be properly registered and inspected, and the firms will have meet rigorous insurance requirements. In a gesture designed to mollify cab drivers, the regulations make clear that passengers can only summon Uber and Lyft cars through their smartphone apps, not by hailing them in the street.

The regulations are a temporary fix; Virginia officials say legislation is needed to codify the new regime. So far, the ride-sharing companies are fine with the rules.

Our support for Uber predates The Post’s purchase last year by Jeffrey P. Bezos, who is an investor in Uber. The logic of encouraging the ride-sharing industry is clear: As anyone who has tried to hail a cab in the rain or at rush hour can attest, taxis are too few and too unreliable to satisfy demand in Washington, as in many other cities. In cities where taxi prices are prohibitive, the new services provide an alternative for passengers, some of whom may have no access to public transit to get to and from work.

Moreover, if ride-sharing companies can offer an attractive and economical alternative to car ownership — which is precisely what they aspire to do — they could induce some people to give up their cars, which would make a dent in traffic and pollution. That would be an important achievement that goes beyond enhanced convenience for well-heeled urban 20-somethings.