Bowing to legal pressure, outgoing Arizona Gov. Doug Ducey agreed to tear down a makeshift wall of double-stacked metal shipping containers he ordered erected on stretches of his state's border with Mexico.

The Republican governor was responding to a lawsuit the Biden administration filed last week alleging the wall was constructed illegally on federal land. Ducey had argued the wall was built in response to Washington's failure to resolve the ongoing migrant crisis.

Ducey and Arizona agreed to halt erecting any more containers along the border and will remove existing containers by Jan. 4.

"By January 4, 2023, to the extent feasible and so as not to cause damage to United States' lands, properties, and natural resources, Arizona will remove all previously installed shipping containers and associated equipment, materials, vehicles, and other objects from the United States' properties in the U.S. Border Patrol Yuma Sector, including from lands over which the U.S. Bureau of Reclamation holds an easement on the Cocopah Indian Tribe's West Reservation," a court document filed Wednesday said.

In addition to trespassing on federal land, the government accused Arizona of damaging vegetation and seasonal streams in a national forest.

The 8,800-pound, 9-by-40-feet containers stand about 22 feet tall when stacked, welded together, and topped with four feet of razor wire, Ducey's office told CNN. Border fencing built during the Trump administration stands about 30 feet high.

Governor spokesperson CJ Karamargin said that Ducey intended the border wall to be a "stopgap measure" and that the state would remove the containers "once the federal government ... took steps to erect a permanent barrier."

"Finally, after the situation on our border has turned into a full-blown crisis, they've decided to act," Karamargin said in a statement.

Democratic governor-elect Katie Hobbs is set to take office in Arizona in January.