Is the choke working alright?...fully open when engine is warmed up? How did the old spark plug tip look?...sooted up/dirty? Plug tip color can tell a lot as to what may be wrong. It sounds like it may be running too rich which is possibly why it runs better just before it dies....as the fuel supply is lessened, the engine returns to a better/leaner fuel-air mixture. If the choke is partially closed or closed, that may be why it's running too rich....not enough air entering engine. Check choke/linkage operation.
But typically, most small engines run too lean as the fuel passages get restricted and clogged from stale fuel/varnish buildup if all else is in good order. In some cases, you have to close the choke or partially to get it to run and restrict air intake since the fuel passages are restricted.
In any event, you may need to adjust the Hi-Lo mixture screws on the carb to get better fuel/air mixtures for low and high speed and disassemble/clean the carb fuel passages and float bowl...check for proper float level. Various websites or Youtube vids show how to clean/adjust carbs for various models. Some carbs have only one mixture screw and some/most have two...one for low speed/idle (usually screw nearest engine on carb body) and one screw for high speed/power...some screws in newer models are limited in adjustment for emissions reasons or need specialty tools to adjust the screws...splined, D shape, Pacman style, etc... Or have a local small engine shop/dealer do it. Most carbs are pretty cheap so it may be better to just get a new one and adjust it for best performance once installed to avoid any issues with fuel passages which may still be clogged on the old one. Just running Seafoam through them does not always work....need to disassemble and soak parts in carb cleaner to get all the crud/varnish buildup out of small passages.