Luckily the firewall can be controlled with the ipfw command on the command line. Take a look at this article at macdevcenter for an example of how to use ipfw.
And, to disable the firewall all that is needed is thus:
sudo ipfw disable firewall
Update: To disable the firewall on Mac OS X 10.5 (Leopard) you can issue the following command:
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 0