KAOHSIUNG, Taiwan—Taiwan’s navy realized a dream it has harbored for four decades in this port city facing the South China Sea. It is 230 feet long, weighs nearly 3,000 tons and is capable of laying mines and attacking warships. Meet the Narwhal, Taiwan’s first domestically-produced submarine—a sleek new weapon that could alter China’s thinking about an invasion if Taipei can afford to produce enough of them. On Thursday, after seven years in the vessel’s making, President Tsai Ing-wen smashed a bottle of Champagne on the submarine, draped with the red, white and blue of Taiwan’s flag to cover its torpedo...