And now the pipeline that once brought foreign oil from the gulf port of Corpus Christi to Three Rivers has been reversed, sending Texas crude to other refineries along the coast for processing into diesel and other products for export far and wide, from Mexico to the Netherlands.

The drilling boom has allowed many refiners to buy crude at a huge discount — sometimes $20 or more a barrel — below international benchmark prices. That is especially true for refineries that operate in the core of the country, where there is a glut of crude from the North Dakota Bakken shale formation because of insufficient pipelines. Historically, until the last couple of years, American crudes typically were priced 50 cents to a dollar higher than international crudes.

The price advantage of United States refiners over their foreign competitors helped the country last year become a net exporter of refined petroleum products for the first time since the late 1940s, producing nearly $10 billion in annual revenue from daily net exports of 370,000 barrels a day of gasoline and diesel.

Over the first eight months of this year, according to the Energy Department, those net exports have surged to 975,000 barrels a day. The country may be able to export another half million barrels of diesel fuel over the next few years, according to Thomas P. Barney, chief economist of Marathon Petroleum.

The export boom is particularly welcome because it comes as demand for gasoline and diesel fuel is sluggish in the United States and American refineries have excess capacity to meet local demands. But global gasoline and diesel demand is still growing, and closings of several Caribbean and European refineries in recent years have opened an opportunity.

“Exports are where the growth is, since most people expect domestic demand to be flat or declining going forward,” said Anthony Rouse, chief economist at Phillips 66, the global refinery giant. Phillips 66 is planning to increase its United States export capacity by 40 percent by the end of next year, he said.