Pirates were in the taking business, not the fighting business. Time and again they proved that they'd rather create a terrifying persona and inspire a quick surrender than slug it out on the high seas. But fights did happen, and vessels became damaged in various ways. It might succumb to stress during a storm, run into a coral reef or some other debris, or simply suffer from rot that caused it to leak badly. What happened when the ship was going down?
First things first- was there a fire? Ships during the Golden Age of Piracy were made of wood, and waterproofed with pitch and tar, and so were about the most flammable things you could imagine. Fortunately fire-prevention measures were a standard part of shipboard life. Exactly where and when open flames could be used was highly regulated. Lanterns were used rather than open candles, pipe smoking was relegated to the open deck, and no fire at all was allowed too close to the gunpowder. The floor and walls of the galley - where a fire was required - were usually lined with tin.
Still, fires happened. During battle, each cannon was supplied with a bucket of water, and a ship going into battle usually had other various barrels and buckets full placed in strategic locations. Often sails would be wetted with sea-water before a fight. This not only reduced the chance of fire, but helped to reduce the porous nature of the canvas, making the sails "draw" better and increasing speed.
If fire broke out, getting the sails out of the way was an early priority. Hot air could dry the fabric fast, allowing it to burst into flame, and the downdraft from the sails might very well fan a fire. Flaming objects could be thrown overboard, and, obviously, all the available water would be thrown at the flames.
If there was time, the ship's pumps would be put into service. Normally, these pumps were used daily to empty any water that had leaked into the ship's lower levels. (All wooden ships leaked a little). The exit hose of the pump could be aimed at the fire. But often, before this could be done, the entire ship would be in flames. Fire was a serious business, and could destroy a ship in minutes.
If that happened, the only thing the crew could do was to get the ship's boats into the water and crowd into them.
If a cannon shot hit below the waterline, or if the ship hit a solid object and was damaged, immediate measures would also need to be taken. The ships were wooden, but they were loaded down with men, supplies, cannons and cargo, and they could sink. Repairing damage was the job of the carpenter, and his expertise could mean the all the difference in keeping the ship afloat.
If there was not an actual hole - if the ship's side was simply battered so much that it had lost integrity and was leaking water, the area of the damage might be shored up with braces, aimed at pushing the ship's timbers back into place. If this worked, then oakum - scraps of old rope that was too worn for use - was pounded into the loosened seams, This sort of repair could be made in the middle of battle, adding to the sense of chaos.
Another action to keep the ship afloat was to position a canvas sling around the outside of the ship, covering the damage like a large bandage. This was a delicate operation, involving the careful placement of ropes and fabric, and often using improvised booms or cranes created from the masts and spars. It required knowing exactly where the damage was, which was not always possible on a crowded ship, and it could not be done during a battle. But it might very well slow the intake of water so the pumps could keep up while more permanent repairs were made.
If the ship took a hole "between wind and water" as the saying went, the main requirement was that debris should be kept out of the way of combatants during the fight. Afterwards, the carpenter might tap into supplies of wood on board, cannibalize other parts of the ship, or stop at a handy island in order to make repairs.
Damage to masts and sails could not sink the ship, but a falling mast could foul all the sails and kill men standing beneath. Furthermore, without sails and the masts to hold them, the ship was not moving, and might be sunk, captured, or driven onto a reef or shore. An immediate response was to cut away downed masts, and to hold damaged masts together with rope bindings, additional ropes to brace the mast and take away strain, and "fishing" the mast, which was basically the equivalent of putting splints on it, in much the way you might splint a broken limb on a person.
When masts were lost, additional pieces of wood - spars, smaller masts - might be hastily tied to the stump. This is one reason why a sailing ship traditionally carried at least one replacement for every mast or spar. A huge main-mast could not be replaced in the heat of battle, but given the slightest opportunity, some sort of jury-rig could be set up, and some sort of canvas could be hung from it to supply power.
In the worst sort of extremity - if a ship had run aground, or taken damage to her hull that was letting in too much water to be controlled, desperate measures were called for. Getting rid of weight was one option, and the first thing to go was often the cannons, At perhaps half a ton apiece, the cannons were a substantial part of the ship's weight. Rolling them off the deck of the ship and into the sea would lighten it considerably, and could allow a badly damaged vessel to escape its pursuer, or stay afloat until repairs could be made.
Cannons lost this way of course, could not be brought back up again.
Cargo could also be thrown overboard, but due to its location and lighter weight, it was not so obvious a solution. Interestingly enough, when pirates came to port with cargo that could not otherwise be explained to the authorities, they often claimed to have picked it up from a ship that was damaged and need to "lighten its load." This was the 18th century equivalent to "it fell off the back of a truck" and fooled no one, but it provided an excuse that could keep pirates out of jail.
If a ship wa not in immediate danger of sinking, her crew could do an amazing number of things to put her back into working order. The number of things that could be done with rope staggers the imagination. Rope cold bind, support, lift, or brace, and it could be made into cushions to fill gaps i wood or rigging, or pad parts that were rubbing together.
A skilled ship's carpenter could virtually re-build the ship from the hull up, given enough time and supplies. Ships carried spare fittings of every time, but also raw wood and unforged iron, which might become anything. And, whenever possible, a ship carried a miniature blacksmith's forge.
Pirates, of course, had one more option. If the pirate ship was too badly damaged in a fight, and the pirates had some means of getting to the enemy ship, they could simply take it. There are several exampled of sinking ships capturing an enemy vessel (their crews would be highly motivated, after all) and marooning that ship's crew. Hoisting the Jolly Roger over a new ship was one way to make sure that what you were standing on was seaworthy.