Pakistan has secured a $6bn bailout from the International Monetary Fund (IMF) as the country battles to stave off an economic crisis.