The residue that results from old fuel being left in the tank can create a restriction in the carburetor. This is why you should always use fresh fuel when filling the tank and a fuel stabilizer to help maintain the quality of the fuel. You can try cleaning the carburetor with carburetor cleaner to eliminate the clog. If cleaning is not effective, you can often purchase a carburetor repair kit to replace some of the components or install a new carburetor altogether.
As fuel is consumed, the level in the fuel tank lowers to make up for this. Fuel caps will have a small vent hole or holes to allow air into the tank, creating a vacuum that can make the engine stop a few seconds. Try loosening the cap slightly then see if you can start the engine. If the engine starts normally and continues to run, it is likely the vent hole or holes in the cap are blocked and the cap will need to be replaced.