The Spanish pedir (“to ask”) comes from the Latin petere, meaning the same.

From that Latin root, we get the English words, petition — which is, after all, merely a formal request.

We can see the mapping in the p‑d of pedir to the p‑t of petition. The t/d are often swapped as languages evolve and are often pronounced similarly as well.