The United States government has lost billions of dollars of oil and gas revenue to fossil-fuel companies because of a loophole in a decades-old law, a federal watchdog agency said Thursday, offering the first detailed accounting of the consequences of a misstep by lawmakers that is expected to continue costing taxpayers for decades to come.

The loophole dates from an effort in 1995 to encourage drilling in the Gulf of Mexico by offering oil companies a temporary break from paying royalties on the oil produced. However, the rule was poorly written, the very politicians who originally championed it have acknowledged , and the temporary reprieve was accidentally made permanent on some wells.

As a result, some of the biggest oil companies in the world, including Chevron, Shell, BP, Exxon Mobil and others, have avoided paying at least $18 billion in royalties on oil and gas drill ed since 1996 , according to a new report from the Government Accountability Office, a nonpartisan agency that works for Congress .

The companies, which hold government leases to drill in the Gulf, continue to extract oil and gas from those wells while not being required to pay royaltie s, a right the industry has gone to court to defend.