You may want to consider shortest-path algorithms that utilize heuristics, such as A*. A heuristic is essentially additional knowledge that can be applied to guide a search.
A* is similar to Dijkstra's, except it chooses the next node to explore by considering 1) the overall cost from the start to the proposed node, and 2) the predicted "value" of the node based on a specified heuristic. If a proposed node has a high value (it appears more likely to reach the destination), it will be chosen first over other options that have the same cost. But as the path is continually explored, the overall cost will increase. Once the cost outweighs the predicted values of the other options, the algorithm will stop exploring this route and will instead try a different one that (now) appears more optimal.
You can see how the chosen heuristic here is crucial, since a better heuristic will be more effective in guiding the algorithm.
You mention that you are given a start point (x1, y1) and end point (x2, y2), so it is possible that a useful heuristic can be the straight-line distance from the current location to the target destination. The idea is that your pathfinder will always want to close the distance between the start point and end point, so the route that appears to bring it closer to the destination will be prioritized over taking side paths.
But, this heuristic is a poor choice if you know in advance that the most direct route will never be the correct path.
As you can see, the "best" shortest-path algorithm is highly dependent on the problem itself. The more that is known about the context, the more likely it is that there exists some optimization that can be used to enhance the algorithm or determine a more ideal heuristic. Unfortunately, without more details, it is difficult to identify these optimizations.