Salah put Liverpool back in front and, despite James Milner being dismissed during the closing stages, Sadio Mane made sure of the three points in added-on time before Max Meyer netted a late consolation.
Liverpool went into the game knowing that they could extend their advantage over Manchester City in the league table, and Jurgen Klopp's side quickly went onto the front foot.
Liverpool were proving to be a danger from set pieces but after Mane, Matip and Virgil van Dijk all failed to make the most of headed opportunities, Palace took a shock lead.
Wilfried Zaha was released down the left flank as the visitors launched a counter-attack and, after reaching the byline, the winger cut the ball back for Townsend to drill a low first-time effort into the net from 12 yards out.
Liverpool went in search of an equaliser before the end of the opening 45 minutes, but Palace reached the break without encountering any more danger and it left Klopp needing to deliver one of his most important team-talks of the season.
The German's words had the desired effect after just 56 seconds. Van Dijk's strike from 30 yards was nothing more than hopeful, but it was deflected into the path of Salah who hooked a volley inside the near post from eight yards out.
Andrew Robertson failed with a long-range effort soon afterwards but Liverpool quickly went ahead through Firmino, who was given the time and space inside the area to turn and send a deflected effort into the far corner.
Liverpool continued to plough forward and it appeared only a matter of time before the league leaders would make sure of the points, but after barely getting out of their own half from the start of the second half, Palace got themselves level.
A corner was delivered to the back post where a group of players were waiting to contest for the ball, and it was Tomkins who rose highest to power a header into the far corner.
Palace sensed that Liverpool were getting nervous - especially at the back - but the home side were soon back in front thanks to an error from stand-in goalkeeper Speroni.
Milner's volleyed cross should have been easily dealt with by Speroni, but the veteran stopper only diverted the ball towards the net and Salah was able to volley home from on the line.
Liverpool had Milner sent off for two poor challenges on Zaha, but Mane made sure of the win in the third minute of added-on time when cutting inside onto his right foot and finding the bottom corner from 10 yards out.
Palace still had time to get a third with Meyer placing a shot past Alisson from 15 yards out after good work from Connor Wickham, but Liverpool were able to hold on to register what could prove to be a significant result come the end of the campaign.
LIVERPOOL (4-3-3): Alisson; Milner, Matip, Van Dijk, Robertson; Henderson, Fabinho (Lallana 87'), Keita (Shaqiri 71'); Mane, Salah (Camacho 94'), Firmino
CRYSTAL PALACE (4-3-3): Speroni; Wan-Bissaka, Tomkins, Sakho, Van Aanholt; Milivojevic, Kouyate (Schlupp 75'), McArthur (Meyer 81'); Townsend, Zaha, Ayew (Wickham 81')