Generally, each country taxes by his own rules. That means that worst case, you do owe taxes in all countries you worked or lived in.
However, most countries have made contracts (treaties) to avoid double taxation. Typically, in the tax declaration for the second country, you enter the amount of taxes already paid in the first country, and the tax gets then lowered to the higher of the two.