Dr. Doolittle and his animal companions find themselves in a precarious situation while sailing home, as their route takes them past the coast of Barbary. The narrative establishes the danger posed by the "Barbary pirates," described as "very bad men" who thrive on causing shipwrecks, stealing cargo, and forcing passengers into rowboats. The pirates are characterized by their arrogance, often returning to shore "singing songs and thinking themselves very clever" after their exploits.
The tranquility of the voyage is shattered when Dab-Dab notices a ship with a "bright red sail" trailing behind them. Dab-Dab immediately senses malevolence, noting, "I don't think it's friendly. I'm worried more trouble is coming our way." The situation escalates when Jip, the dog, begins to "growl and talk in his sleep." Jip’s extraordinary sense of smell allows him to detect the threat long before it is visible, as he mumbles, "I smell bad men, the worst men I ever smelled. I smell trouble."
As the pirate ship closes the gap, Dr. Doolittle attempts to outpace the pursuers by setting more sails. Despite the crew's best efforts, the pirate ship proves to be "faster" and continues to "gain on the doctor's ship." The animals observe the approaching vessel with growing alarm, noting that the pirates are "almost on top of us now." With the situation becoming dire, the doctor realizes they need an unconventional solution to evade capture.
Dr. Doolittle calls upon the swallows for assistance. Following their instructions, the crew unraveled "long rope" into "thin strips," which were then attached to the front of the ship. In a remarkable display of teamwork, two thousand swallows—two for every one of the "thousand strings"—took flight, pulling the vessel behind them. The impact was instantaneous; the ship began moving so rapidly that the doctor "had to hold onto his hat with both hands." The speed was so great that it "felt almost like they were flying." Ultimately, the clever maneuver proved successful, as the pirate ship with the "red sail" was left "far, far behind," allowing the doctor and his friends to escape the clutches of the pirates and continue their journey safely.