What's the best play when you're losing? When you're down a few pieces or even in a bad position, which is better, playing offensive or defensive?
Usually when you are decisively down in material, the best option is to make the position as complicated as possible. If you don't create any threats, your opponent doesn't have a chance to go wrong. And if nothing special happens, you are going to lose. So stir it up, create a mess, chaos on the board and suddenly everything is possible again, especially if you're opponent tries to play it super safe and gets low on time.

If your position is just somewhat worse, however, lashing out with some sacrifices often makes it much easier for your opponent to finish you off. So dogged defence against all tactical possibilities is often a better try in such a situation. 

Of course if your position is somewhere between worse and lost, it is often hard to decide which way to go. Miss too many chances to mess it up and suddenly you're dead lost. Mess it up to early and suddenly you get messed up. ;-)

One final tip: Try to be ahead on the clock. It is a very common scenario that you defend very well for a long time, and just when the position is equal again, you blunder the game away, because you're low on time. 

An example by the current World Champ:
Carlsen-Topalov, 2012:
Incredibly Carlsen just overlooked 20…Nb2, as he said after the game, but he immediately sacrificed a lot more material to get an attack going. Objectively this shouldn't have been enough, but he created enough chaos to eventually confuse Topalov and in the end even win the game.

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
1. e4 c5 2. Nf3 d6 3. Bb5+ Nd7 4. c3 Ngf6 5. Qe2 a6 6. Ba4 Qc7
7. O-O e5 8. d4 b5 9. Bc2 cxd4 10. cxd4 Be7 11. Nc3 O-O
12. Bg5 h6 13. Bh4 Bb7 14. Rad1 Rac8 15. Bb3 Rfe8 16. dxe5
dxe5 17. Bg3 Bf8 18. h3 Nb6 19. Nh4 Nc4 20. Nf5 Nxb2 21. Bh4
Nxd1 22. Bxf6 Nxc3 23. Qg4 Bxe4 24. Nxh6+ Kh7 25. Bxf7 Qxf7
26. Nxf7 gxf6 27. f4 Bg6 28. Qh4+ Kg7 29. fxe5 Ne4 30. Rxf6
Bc5+ 31. Kh2 Nxf6 32. Qxf6+ Kh7 33. Ng5+ Kh6 34. Ne6 Rxe6
35. Qxe6 Re8 36. Qf6 Be7 37. Qxa6 b4 38. Qc4 Bf8 39. g4 Kh7
40. e6 Bd6+ 41. Kg2 Be7 42. Qc7 Kg8 43. Kg3 Kf8 44. Qf4+ Kg7
45. Qd4+ Kg8 46. h4 Rd8 47. Qc4 Bd3 48. Qc6 Bb1 49. h5 Bxa2
50. Qe4 Kh8 51. h6 Bf6 52. e7 Re8 53. Qf4 Bg7 54. hxg7+ Kxg7
55. g5 Kg8 56. Qf6 1-0