Your question touches a trial well known to the people of God, and you are not alone in having felt it. You have kept a matter in prayer, and the Lord has delivered you, but as you say, at the last possible minute, when the water was at its deepest, and then as soon as the mercy has come, another dart has been shot at you to steal away the comfort of it. There is wisdom in asking why the Lord orders it so.
First, know that you have a waiting God. The prophet says, Therefore will the Lord wait, that He may be gracious unto you. He waits on high that He may have mercy. He is not slow as men count slowness, nor is He unkind in His delay. He waits that the deliverance, when it comes, may be seen to be His own work. If the answer came at your first asking, you might think your own hand had wrought it. When He brings you forth, it must be with His hand and outstretched arm alone, that you may say, He brought them forth. So He lets the need become great, that the grace may appear the greater.
There is a second reason. As you wade into the stream of trouble, at first it is ankle deep, anon it becomes breast high, and you comfort yourself with the promise, When thou passest through the waters I will be with thee. Yet you sink and the water becomes deeper still, till you are in the very deepest part of the stream. It is there, in that deepest place, that faith is tried and proved. The Lord keeps you waiting that you may learn to wait only upon God, not upon the arm of flesh nor upon any changeable creature. Blessed are all they that wait for Him, and His waiting people wait expectantly and patiently, looking for everything from Him who is their All in All. The anxiety of which you speak, that doubtful mind that wonders how it will turn out, is the very thing the Lord would have you lay aside. Neither be ye of a doubtful mind, says the Saviour. You have to do the right thing, to keep the matter in prayer as you have done, and then to leave the result with God. That is His business. Your business is to trust.
You ask why He permits the anxiety. It is that you may learn that doubting the truth of His promise is one thing, and questioning whether that promise is made to you is another. He would have you come to know that His Law written upon the new heart preserves you, and the heart preserves the writing. In your last expiring moments as well as in this present trouble, that writing remains. He is teaching you to remember the years of the right hand of the Most High. When present comfort fails, you are to say, This is my infirmity, but I will remember what He has done. Every former deliverance becomes a song to cheer you in the next night of waiting.
And as to that second pattern you have observed, that as soon as the victory looks at hand the adversary counters to steal some of it away, this also is no strange thing. Just when you are in the deepest part of the stream, Satan appears upon the bank and shoots this fiery arrow, Thy God hath forsaken thee. And when deliverance has come, he will toss the surface of the ocean into an apparent storm, though all may be still and calm down in the caverns beneath. He cannot undo what God has done, but he can, if permitted, rob you of the song that should follow it. That is why we are told to be much in supplication, for he that is mighty on his knees is mighty everywhere, and why after every mercy we should set up our Ebenezer and sing our songs of deliverance, lest the enemy steal the joy of the conquest.
What then shall you do. Keep on praying, and keep on waiting. Do not go limping along all your life when you might run in the way of His commandments. Tighten the harp strings again. Call to remembrance your song in the night. Reckon that if He has found a ransom and delivered you from going down to the pit once, He will do it again. He has said, I will give you a new heart, I will forgive your sins, I will keep you holy, I will preserve you in My ways, I will bring you to Myself at the last. If He has written this upon your heart, it will not be erased.
Therefore wait upon the Lord. His delays are not denials, they are preparations for a more gracious display of His power. The squeaker, as you call it, the narrow escape, is in truth a mighty deliverance, made narrow only that you may see how wide His mercy is. Let the anxiety be turned into expectancy, and let the counter attack of the devil drive you not from your victory but closer to Him who gave it.