MADRID — First it couldn’t float. Now, it can’t dock.

The Spanish military’s new submarine has been plagued by engineering problems and cost overruns during development, and the government will end up spending millions more than it had planned for the project.

Years ago, the S-80 submarine suffered a major engineering setback: It was overweight and at risk of not being able to resurface after submerging. In the latest hitch, first reported on Wednesday by the newspaper El País, it can’t fit into the port of Cartagena at the military base in southeastern Spain where the submarine will be stationed.

Margarita Robles, the country’s defense minister, acknowledged on Wednesday that there had been “deficiencies in the project,” but she insisted it remained “absolutely viable.”

Navantia, the state-controlled shipbuilder contracted by the government to build the submarine, could not immediately be reached for comment.