Balance of payments is composed of:
- the capital account (foreign assets and foreign liabilities)
- and current account (includes exports and imports)
One way to define the current account is savings minus domestic investment, $S-I$. When $S<I$, a country's investing has to be financed by capital inflows, or investment from foreign countries. This is a deficit on the current account, making the country a net borrower that must seek matching capital inflows like foreign direct investment, that are a credit on the capital account (capital account surplus).
Whereas, when $S>I$, the excess savings are used to invest in foreign opportunities abroad, creating a current account surplus that makes the country a net lender, giving a capital account deficit.
In relation to the current account, a trade deficit is not identical but is a component of the current account. When there is a current account deficit, a trade deficit happens (imports exceed exports, where imports are not to be confused with investments $I$) because the country does not produce everything it needs and needs to borrow from overseas in order to pay for imports. From Greg Mankiw:
when we write Y=C+I+G+NX, what is NX? The answer depends on how we define Y. If Y is Gross Domestic Product, then NX is the trade balance. If Y is Gross National Product, then NX is the current account.
Even though a trade deficit sounds bad, standard of living usually increases from a wider variety of imported goods and services, and prices are pushed downwards curbing inflation, but only for so long.