Texas has been flexing its global oil muscles.

For the first time, the Lone Star state's biggest port district recently exported more crude oil than it imported, according to the Energy Department.

It's a big achievement that highlights a surge in US oil exports, and that shows how the shale boom can make America less reliant on foreign oil.

"It's a definite milestone. Nobody saw this coming 10 years ago," said Bob McNally, president of consulting firm Rapidan Energy Group and a former energy official under President George W. Bush. "It's an unambiguously good thing. It diversifies our dependence from the volatile Middle East."

Texas is the epicenter of the shale revolution, with soaring production in the oil-rich Permian Basin leading the United States to record output. Rapid technological advances in fracking, the process of unlocking oil and gas deep underground, have dramatically reduced the cost to drill oil in the Permian Basin.

Texas is now on track to produce more oil than either Iran or Iraq. That would make Texas No. 3 in the world if it were a country.

In April, exports out of the Houston-Galveston port region exceeded imports by 15,000 barrels per day, statistics from the US Energy Information Administration show. That's a huge reversal from the gap of nearly 1 million barrels in December 2015, when a federal ban on oil exports was lifted by Congress.

The trade surplus in Houston-Galveston spiked to 470,000 barrels per day in May, the Energy Department said. Total US oil exports climbed to a record high of 2 million barrels per day that month.

"I'm very proud. It shows the repositioning of Texas in the global oil market," said Ryan Sitton, a commissioner on the Texas Railroad Commission, which regulates the state's sprawling oil and gas industry.

Gulf Coast bulks up for exports

The Houston-Galveston region comprises multiple ports of entry along the Texas Gulf Coast, including Houston, Texas City, Freeport and Corpus Christi. It's the No. 1 region in the United States for oil exports, accounting for nearly three-quarters of the nation's shipments in May. Leading destinations include Canada, China, India, Italy and the United Kingdom.

The US Gulf Coast has been racing to build infrastructure -- including wider shipping channels and revamped terminals -- to handle foreign demand for America's shale oil. In June, the Port of Corpus Christi, Texas, approved a $217 million bond package that will be used to handle soaring energy exports.

But there are limitations. Most of the ports along the US Gulf Coast are unable to load the supertankers that carry crude around the world. The Louisiana Offshore Oil Port is the only deep-water port in the United States that can handle the super tankers.

US on track to become net energy exporter

The United States still relies on foreign oil -- but not as much.

The gap between oil imports and exports shrank to a 24-year low of 6.8 million barrels per day in 2017, according to the EIA. Even though the economy is stronger, US oil imports fell to 7.8 million barrels per day in May. That's down from more than 9 million barrels per day as recently as mid-2012.

Despite the recent milestone from the Houston-Galveston region, McNally doesn't think the United States will export more oil than it imports any time soon. That's because US oil refineries require a steady dose of the heavy crude found abroad. They can only take so much of the lighter blend of oil that comes out of the Permian Basin.

"Our complex refinery system structurally commits us to being at least a small net importer of oil," said McNally.

But declining US oil imports are helping the overall energy trade balance.

The shale boom already made the United States a net exporter of natural gas in 2017. And the EIA recently predicted that the United States will become a net energy exporter in 2022. That achievement could come as early as 2020 if oil prices are high.