The Floyd-Warshall algorithm finds the shortest paths between all pairs of vertices in a weighted graph. It works by computing the shortest path between every pair of vertices through dynamic programming. The algorithm proceeds in steps, where in each step it considers all vertices as potential intermediate vertices to find even shorter paths between vertex pairs. This is done by comparing the newly computed shortest paths to the values stored in the previous matrix.